Hello,
I am literally banging my head against the wall trying to figure out how to
use the tab key to move from the last column in a datagrid row to the first
column in the next row when that first column is a Custom DataGridColumnStyle
(in this case, as combobox). I have seen George Shepherd's suggestion on
subclassing the embedded control, and have tried three different ways of
doing this, as shown below. NONE of them work.
I think I know why...
After having tabbed through my datagrid, when I then look at the trace
for "Debug.WriteLine(keyData.ToString)", I see Tab for every move I made from
one column to the next ON THE SAME ROW. But when my tab key cause a new row
to become current, my debug trace shows nothing at all.
Question is, how to solve this problem. Can anyone enlighten me as to
exactly how the datagrid moves to a new row in response to the tab key?
Maybe if I can understand that, I can achieve what I am trying to achieve.
Thanks.
Public Class DataGridComboBox
Inherits ComboBox
Public Sub New()
MyBase.New()
End Sub
Public isInEditOrNavigateMode As Boolean = True
Protected Overrides Function ProcessDialogKey(ByVal keyData As
System.Windows.Forms.Keys) As Boolean
Dim dG As DataGrid = DirectCast(Me.Parent, DataGrid)
Dim curCell As DataGridCell = dG.CurrentCell
With curCell
Dim cNum As Integer = .ColumnNumber
Dim colIndex As Integer = dG.TableStyles(0).GridColumnStyles.Count - 1
Debug.WriteLine(keyData.ToString)
If keyData = Keys.Tab Then
'No more columns in row --> go to nbew row
If cNum = colIndex Then
dG.CurrentCell = New DataGridCell(.RowNumber + 1, 0)
Return True
'More columns in current row
Else
'Tab normally
dG.CurrentCell = New DataGridCell(.RowNumber, .ColumnNumber + 1)
Return True
End If
End If
End With
Return MyBase.ProcessDialogKey(keyData)
End Function
'Private WM_KEYUP As Integer = &H101
'Protected Overrides Sub WndProc(ByRef m As System.Windows.Forms.Message)
' If m.Msg = WM_KEYUP Then
' Return
' End If
' MyBase.WndProc(m)
'End Sub
'Protected Overrides Sub WndProc(ByRef m As System.Windows.Forms.Message)
' If m.WParam.ToInt32 = CInt(Keys.Tab) Then
' Return
' End If
' MyBase.WndProc(m)
'End Sub
'Private Sub DataGridComboBox_KeyDown(ByVal sender As Object, ByVal e As
System.Windows.Forms.KeyEventArgs) Handles MyBase.KeyDown
' If e.KeyData = Keys.Tab Then
' e.Handled = True
' End If
'End Sub
End Class
--
John