Groups | Blog | Home
all groups > vb.net controls > june 2004 >

vb.net controls : Determining the current DataGridColumnStyle


Dave Taylor
6/29/2004 3:27:55 PM
I have a DataGridColumnStyle-derived class that implements a ComboBox. I've
also derived a DataGrid class and overrode the ProcessKeyPreview method to
return False when the tab key is pressed (avoiding the issue caused by
pressing the tab key and having it fly by the custom column style). I would
also like to not process the Up/Down arrow keys when the current column type
is my custom class. Is there a way to determine the current
DataGridColumnStyle? I see the CurrentCell property of the DataGrid, and it
has a ColumnNumber property, but in order for that to be useful, I would
need the current TableStyle.

Thanks
Dave Taylor

Dave Taylor
6/29/2004 3:55:39 PM
BTW...currently, I have the following code which works quite well except for
the fact that it is limited to a DataGrid that contains one and only one
TableStyle...so how do I make this more portable by detecting the current
TableStyle?

Public Class DataGridNPV

Inherits DataGrid

Protected Overrides Function ProcessKeyPreview(ByRef m As
System.Windows.Forms.Message) As Boolean

Const WM_KEYUP As Integer = &H101

Const VK_TAB As Integer = &H9

Const WM_KEYDOWN As Integer = &H100

Const VK_UP As Integer = &H26

Const VK_DOWN As Integer = &H28

Dim bDisableUpDown As Boolean = False

'Determine if the column being edited has the DataGridUnitsColumn
style,

'if so, then do not process Up/Down arrow keys

If Me.TableStyles.Count > 0 Then

With Me.TableStyles(0)

Dim cs = .GridColumnStyles(Me.CurrentCell.ColumnNumber())

If TypeOf cs Is DataGridUnitsColumn Then bDisableUpDown =
True

End With

End If

If (m.Msg = WM_KEYUP) Or (m.Msg = WM_KEYDOWN) Then

If m.WParam.ToInt32 = CType(VK_TAB, Int32) Then Return False

If bDisableUpDown And ((m.WParam.ToInt32 = CType(VK_UP, Int32))
_

Or (m.WParam.ToInt32 = CType(VK_DOWN, Int32))) Then
Return False

Return MyBase.ProcessKeyPreview(m)

End If

End Function

End Class



[quoted text, click to view]

AddThis Social Bookmark Button