程序如下:
Private Rs As ADODB.Recordset 
Private Sub Form_Load()
    Set Rs = New ADODB.Recordset
    Rs.Open "select 1,2 from a", g_Connection, adOpenKeyset,  adLockBatchOptimistic
    Set Datagrid1.DataSource = Rs
    
End Sub
Private Sub Datagrid1_KeyPress(KeyAscii As Integer)
      If Datagrid1.Col = 0 Then
         If Len(Trim(Datagrid1.Columns(0).Text)) = 1 Then
             Datagrid1.Col = 1
      End If
    End If
End Sub
Private Sub CmdAdd_Click()
     Dim I As Integer
     For I = 1 To 10
        Rs.AddNew
        Rs.Fields!1 = ""
        Rs.Fields!2 = ""
     Next I
    
    
End Sub我大概的意思是向一个绑定的datagrid中先添加10条空的记录,然后在这些空的记录中输入数据,当我向0列输入一个1个字符长的值后,再输入字符时,焦点要自动跳到第1列。现在的问题是当焦点跳到第1列时,第0列输入的数据也跟着一起跳到1列,不知到是什么原因?如果可以的话,你也把我的程序执行一下,看看是不是这个情况?这个问题该如何解决,那位朋友知道请指教!万分感谢,裸体再谢!

解决方案 »

  1.   

    '我试了一下,真是奇怪,只好用土办法,先将数据保存起来再覆盖。你试试吧,不过我调试是过了
    Dim strTmpLeft$, strTmpRight$Private Sub DataGrid1_AfterColEdit(ByVal ColIndex As Integer)
        DataGrid1.Columns(1).Text = strTmpRight
    End SubPrivate Sub DataGrid1_KeyDown(KeyCode As Integer, Shift As Integer)
        If DataGrid1.Col = 0 Then
            strTmpLeft = DataGrid1.SelText
            If Len(Trim(DataGrid1.Columns(0).Text)) = 1 Then
                DataGrid1.Columns(0).Text = strTmpLeft
                strTmpRight = DataGrid1.Columns(1).Text
                DataGrid1.Col = 1
                SendKeys "{enter}"
            End If
        End If
    End Sub
      

  2.   

    将这一句strTmpLeft = DataGrid1.SelText
    改成strTmpLeft = DataGrid1.Columns(0).Text更保险