Combo Box in .Net Data Grid

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • surf2mail@gmail.com

    #1

    Combo Box in .Net Data Grid

    To anyone trying to solve the dropdown combo box navigation in a .net
    grid problem, here is one solution - hey, it works:

    We neet to trap key down and up (arrow) events and use them to
    navigate the combo box rather than navigate the grid. Don't want to
    be forced to use the mouse to navigate the combo box. So here is the
    solution:

    Create the following class which inherits the Combo box.


    Public Class NoKeyUpCombo
    Inherits ComboBox
    Private WM_KEYUP As Integer = &H101
    Const WM_KEYDOWN As Integer = &H100

    Protected Overrides Function ProcessCmdKey(B yRef msg As Message,
    ByVal keyData As Keys) As Boolean
    need this function to be able to capture the Down/Up arrow
    keys
    ''prevents the cell from changing so we can navigate the combo
    box
    Dim currentCell As DataGridCell
    Dim iSel As Int16
    Dim iMax As Int16
    'System.Diagnos tics.Debug.Writ e(keyData)
    'System.Diagnos tics.Debug.Writ e(keyData.ToStr ing)
    If Me.Items.Count < 1 Then
    Return True
    End If
    Try
    If keyData.ToStrin g = "Down" Then
    iMax = Me.Items.Count
    If Me.SelectedInde x < iMax - 1 Then
    iSel = Me.SelectedInde x + 1
    Me.SelectedInde x = iSel
    End If
    End If
    If keyData.ToStrin g = "Up" And Me.SelectedInde x 0 Then
    iSel = Me.SelectedInde x - 1
    Me.SelectedInde x = iSel
    End If
    Catch ex As Exception
    'Throw ex
    Me.SelectedInde x = -1

    End Try
    End Function

    Protected Overrides Sub WndProc(ByRef m As
    System.Windows. Forms.Message)
    If m.Msg = WM_KEYUP Or m.Msg = WM_KEYDOWN Then
    'ignore keyup/down to avoid problem with tabbing &
    dropdownlist;


    Return
    End If

    MyBase.WndProc( m)

    End Sub 'WndProc


    End Class 'NoKeyUpCombo

    '''hope this helps, -Peter

Working...