我使用vb的datagrid来进行数据库的插入修改,我想在修改一个记录后按回车直接跳到下一行,如果当前是最后一行默认进行添加记录操作,请高手帮帮忙

解决方案 »

  1.   


    给你点代码自己改改吧,
    Private Sub DataGrid1_Click()
        With DataGrid1        Text2.Visible = True
            If .Col < 0 Then Exit Sub
            If .Row < 0 Then Exit Sub
            a = .Row: b = .Col        Text2.Move .Columns(.Col).Left + .Left, .RowTop(.Row) + .Top, .Columns(.Col).Width, .RowHeight
            Text2.BackColor = &HC0FFC0
            Text2 = ""
            Debug.Print .Columns(.Col).CellText(.RowBook(.Row))
            If .Columns(.Col).CellText(.RowBook(.Row)) = "" Then
               Text2.Text = ""
            Else
               Text2.Text = .Columns(.Col).CellText(.RowBook(.Row))
            End If
            Text2.SelLength = Len(Text2.Text)
            Text2.SetFocus
        End With
    End SubPrivate Sub Text2_KeyPress(KeyAscii As Integer)
        If KeyAscii <> 13 Then Exit Sub
        If Text2.BackColor = &HC0FFC0 Then
            Text2.Visible = False
            DataGrid1.SetFocus
            DataGrid1.SelStartCol = b
            DataGrid1.SelStart = 0
            
            DataGrid1.SelLength = Len(DataGrid1.Columns(b).CellText(DataGrid1.RowBook(a)))
            
            DataGrid1.Text = Text2.Text
        End If
        
    End Sub