Posted by: Sourav | June 1, 2015

Detect Enter or Tab and populate your gridview accordingly in VB.Net


Private Sub DataGridView4_KeyPress(sender As Object, e As KeyPressEventArgs) Handles DataGridView4.KeyPress
        If e.KeyChar = Microsoft.VisualBasic.ChrW(Keys.Return) Then
            Dim currCell As DataGridViewCell = DataGridView4.CurrentCell

            Dim row As New DataGridViewRow
            If Not Me.DataGridView4.Rows(currCell.RowIndex) Is Nothing Then
                row = Me.DataGridView4.Rows(currCell.RowIndex)
                TextBox10.Text = (row.Cells(“ID”).Value.ToString)
                TextBox11.Text = (row.Cells(“Name”).Value.ToString)
                TextBox12.Text = (row.Cells(“Age”).Value.ToString)
                TextBox13.Text = (row.Cells(“Username”).Value.ToString)
                TextBox14.Text = (row.Cells(“Password”).Value.ToString)
                If (row.Cells(“Active”).Value.ToString) = True Then
                    CheckBox2.Checked = True
                Else
                    CheckBox2.Checked = False

                End If

            End If
            e.Handled = True
        End If
        If e.KeyChar = Microsoft.VisualBasic.ChrW(Keys.Tab) Then
            Dim currCell As DataGridViewCell = DataGridView4.CurrentCell

            Dim row As New DataGridViewRow
            If Not Me.DataGridView4.Rows(currCell.RowIndex) Is Nothing Then
                row = Me.DataGridView4.Rows(currCell.RowIndex)
                TextBox10.Text = (row.Cells(“ID”).Value.ToString)
                TextBox11.Text = (row.Cells(“Name”).Value.ToString)
                TextBox12.Text = (row.Cells(“Age”).Value.ToString)
                TextBox13.Text = (row.Cells(“Username”).Value.ToString)
                TextBox14.Text = (row.Cells(“Password”).Value.ToString)
                If (row.Cells(“Active”).Value.ToString) = True Then
                    CheckBox2.Checked = True
                Else
                    CheckBox2.Checked = False

                End If

            End If
            e.Handled = True
        End If
       
    End Sub

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

Categories

%d bloggers like this: