How can avoid Tab navigation on cells in Datagrid. ? I want Tab keys acts as
Control navigation.
TIA
Antonio
> How can avoid Tab navigation on cells in Datagrid. ? I want Tab keys acts
> as Control navigation.
Hi Antonio,
I managed to do this by subclassing datagrid and then overriding the
ProcessCmdKey method. Here you check if the Tab key was pressed
(sets tabPressed) and check which modifiers (Alt, Ctrl, Shift) were
pressed (e.g forward = (shiftPressed = False) )
Then do the tabbing yourself using the following:
If tabPressed then
Me.TopLevelControl.SelectNextControl(Me, forward, True, True, True)
Return True
Else
Return MyBase.ProcessCmdKey(msg, keyData)
Endif
This only works well on read-only grids. In our grid some columns are
read-write in which case the tabbing has a different behaviour,
it skips the readonly cells and jumps to the next (or previous)
editable cell (possibly in the next row). This really sucks but it
works ok now. A shame that there's so much stuff you have to yourself
in the datagrid (e.g. Single selection, selection changed event and
and and...)
ALso have a look at http://www.syncfusion.com/faq/winforms. Lots of
grid stuff too.
HTH,
Marius.
Antonio Paglia - 24 Aug 2005 14:43 GMT
Ok Marius .
I understood ProcessCmdKey method.
Now the question is how to subclass a Datagrid. All samples that I have
seen, show how intercepting Form messages, but I don't kwnow how catch only
Datagrid msg. I have tried Spy++ to view Datagrid msg, but I don't know how
identify the Tab Pressed inside Datagrid.
Protected Overrides Sub WndProc(ByRef m As System.Windows.Forms.Message)
MyBase.WndProc(m)
???
End Sub
Can you orient to me ?
TIA
>> How can avoid Tab navigation on cells in Datagrid. ? I want Tab keys acts
>> as Control navigation.
[quoted text clipped - 28 lines]
> HTH,
> Marius.
Marius Groenendijk - 24 Aug 2005 15:53 GMT
> I understood ProcessCmdKey method.
> Now the question is how to subclass a Datagrid. All samples that I have
> > seen, show how intercepting Form messages, but I don't kwnow how catch
> only Datagrid msg. I have tried Spy++ to view Datagrid msg, but I don't
> know how identify the Tab Pressed inside Datagrid.
> Can you orient to me ?
Antonio,
I hope the following VB.NET code snippet works
In C# it's of course exactly the same except for the syntax :-)
Everywhere you'd use the normal DataGrid you can simply replace it
with NoTabDataGrid.
You will notice that you might also need to intercept (ignore) the
keypad Left and Right arrows as they have a tab-like behaviour in the
grid.
Adios,
Marius.
---------
Public Class NoTabDataGrid
Inherits System.Windows.Forms.DataGrid
Public Sub New()
' do your own construction stuff here if necessary
MyBase.New()
End Sub
Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)
' do your own cleanup stuff here if necessary
MyBase.Dispose(disposing)
End Sub
Protected Overrides Function ProcessCmdKey(ByRef msg As
System.Windows.Forms.Message, _
ByVal keyData As System.Windows.Forms.Keys) As Boolean
Dim tabbing As Boolean
Dim forward As Boolean
' See if shift was pressed
Dim shift As Boolean = ((keyData And Keys.Shift) = Keys.Shift)
' Get rid of the modifiers
Dim theKey As Keys = keyData And (Not Keys.Modifiers)
If theKey = Keys.Tab Then
tabbing = True
forward = (Not shift) ' Shift-Tab = backward
End If
If tabbing Then
Me.TopLevelControl.SelectNextControl(Me, forward, True, True, True)
Return True
Else
Return MyBase.ProcessCmdKey(msg, keyData)
End If
End Function
End Class
Antonio Paglia - 25 Aug 2005 13:00 GMT
Marius,
You are Great !
Muchas Gracias !
Antonio
>> I understood ProcessCmdKey method.
>> Now the question is how to subclass a Datagrid. All samples that I
[quoted text clipped - 60 lines]
>
> End Class