Below is code I have written to capture when the tab key is pressed inside of a two-column data grid view. The only problem I'm having is that I have to press the tab key twice for this event to fire. Would anybody know why this is. Any help you can provide is greatly appreciated...
Code:Private Sub dgvCustomerIncludes_PreviewKeyDown(ByVal sender As Object, ByVal e As System.Windows.Forms.PreviewKeyDownEventArgs) Handles dgvCustomerIncludes.PreviewKeyDown If e.KeyValue = 9 Then For X As Integer = 0 To (dgvCustomerIncludes.Rows.Count - 1) If Not Trim(dgvCustomerIncludes.Rows(X).Cells(0).Value) = "" And Trim(dgvCustomerIncludes.Rows(X).Cells(1).Value) = "" Then '''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''' ' customer id with no customer name so call function GetCustomerName ' '''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''' dgvCustomerIncludes.Rows(X).Cells(1).Value = GetCustomerName(Trim(dgvCustomerIncludes.Rows(X).Cells(0).Value)) dgvCustomerIncludes.Refresh() ElseIf Trim(dgvCustomerIncludes.Rows(X).Cells(0).Value) = "" And Not Trim(dgvCustomerIncludes.Rows(X).Cells(1).Value) = "" Then '''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''' ' customer id was deleted but name is still there so erase the customer name ' '''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''' dgvCustomerIncludes.Rows(X).Cells(1).Value = "" dgvCustomerIncludes.Refresh() End If Next X End If End Sub




Reply With Quote
