Click here to Skip to main content
15,887,454 members
Home / Discussions / Visual Basic
   

Visual Basic

 
GeneralRe: fill combo box with table items Pin
Pablo.ar24-Nov-04 2:56
Pablo.ar24-Nov-04 2:56 
GeneralRe: fill combo box with table items Pin
jlawren724-Nov-04 4:40
jlawren724-Nov-04 4:40 
GeneralRe: fill combo box with table items Pin
ccotton33324-Nov-04 6:51
ccotton33324-Nov-04 6:51 
Generalvb.net, textbox connected with database Pin
Member 149603823-Nov-04 8:32
Member 149603823-Nov-04 8:32 
GeneralRe: vb.net, textbox connected with database Pin
jlawren723-Nov-04 12:36
jlawren723-Nov-04 12:36 
GeneralRe: vb.net, textbox connected with database Pin
Anonymous2-Dec-04 14:28
Anonymous2-Dec-04 14:28 
GeneralRe: vb.net, textbox connected with database Pin
Member 14960382-Dec-04 14:31
Member 14960382-Dec-04 14:31 
GeneralIssue with Keyboard Handling Pin
rascalot23-Nov-04 5:31
rascalot23-Nov-04 5:31 
I am trying to resolve a problem with keyboard handling for an Windows Forms application that consists of a number of datagrids. Adding and deleting records is allowed only with button actions. The datagrids contain combobox columns. Column navigation is by TAB/Shift-TAB and RIGHT/LEFT Arrows. I am trying to achieve keyboard control for the combobox columns as follows:

Press ENTER for first time in the combobox column drops the list (droppeddown=true), UP/DOWN Arrows navigates the list, press ENTER again closes the drop (droppeddown=false) and selects the value. I am able to get the combobox to drop on the first ENTER press, navigate UP/DOWN the list, but cannot catch the second ENTER to close the dropdown. The only way to exit the combo is TAB or ARROW.

I am using the KeyUp event for the ComboBoxColumn and some message code for the ComboBox. There seems to be some sort of conflict here that I cannot figure out. Any help would be appreciated.

Here is my code that I am using in both the ComboBoxColumn and in the extended ComboBox:

ComboBox Code:


Public Class NoKeyUpCombo <br />
    Inherits CompletionCombo <br />
    Private Const WM_KEYUP As Integer = 257 <br />
    <br />
    Protected Overloads Overrides Function ProcessKeyMessage(ByRef m As Message) As Boolean <br />
        Dim key As Keys = CType(CType(m.WParam.ToInt32, Integer), Keys) <br />
        <br />
        Select Case key <br />
            Case Keys.Tab <br />
                Return True <br />
            Case Keys.Up, Keys.Down <br />
                Return False <br />
            Case Else <br />
                Return MyBase.ProcessKeyMessage(m) <br />
        End Select <br />
    End Function <br />
<br />
    Protected Overloads Overrides Function IsInputKey(ByVal key As Keys) As Boolean <br />
        Select Case key <br />
            Case Keys.Up, Keys.Down <br />
                Return True <br />
        End Select <br />
        Return MyBase.IsInputKey(key) <br />
    End Function



ComboBoxColumn Code:

Private _ColumnComboBox As NoKeyUpCombo<br />
<br />
    AddHandler _ColumnComboBox.KeyUp, AddressOf ComboBoxKeyUp <br />
    AddHandler _ColumnComboBox.KeyDown, AddressOf ComboBoxKeyDown <br />
<br />
  <br />
    Private Sub ComboBoxKeyDown(ByVal sender As Object, ByVal e As KeyEventArgs) <br />
        If e.KeyCode = Keys.Enter Or e.KeyCode = Keys.Execute Or e.KeyCode = Keys.Return Then <br />
            Dim cbx As NoKeyUpCombo = CType(sender, NoKeyUpCombo) <br />
            cbx.SelectedIndex = _SelectedIndex <br />
            Debug.WriteLine(_ColumnComboBox.SelectedIndex.ToString & "KeyDown-ENTER:" & _ColumnComboBox.Text) <br />
            e.Handled = False <br />
        End If <br />
    End Sub <br />
<br />
    Private Sub ComboBoxKeyUp(ByVal sender As Object, ByVal e As KeyEventArgs) <br />
        Dim i As Integer <br />
        If Not _ColumnComboBox.DroppedDown Then <br />
            If e.KeyCode = Keys.Enter Or e.KeyCode = Keys.Execute Or e.KeyCode = Keys.Return Then <br />
                _ColumnComboBox.DroppedDown = True <br />
                KeyStrokeProcessed = True <br />
                _ColumnComboBox.Invalidate() <br />
                _ColumnComboBox.Update() <br />
            End If <br />
        Else <br />
            Select Case e.KeyCode <br />
                Case Keys.Down <br />
                    i = _ColumnComboBox.SelectedIndex <br />
                    If _ColumnComboBox.Items.Count > i Then <br />
                        _SelectedIndex = i + 1 <br />
                        _ColumnComboBox.SelectedIndex = _SelectedIndex <br />
                        _ColumnComboBox.Invalidate() <br />
                        _ColumnComboBox.Update() <br />
                        e.Handled = False <br />
                        Debug.WriteLine(_ColumnComboBox.SelectedIndex.ToString & "-Down:" & _ColumnComboBox.Text) <br />
                    End If <br />
                Case Keys.Up <br />
                    i = _ColumnComboBox.SelectedIndex <br />
                    If i > 0 Then <br />
                        _SelectedIndex = i - 1 <br />
                        _ColumnComboBox.SelectedIndex = _SelectedIndex <br />
                        _ColumnComboBox.Invalidate() <br />
                        _ColumnComboBox.Update() <br />
                        e.Handled = False <br />
                        Debug.WriteLine(_ColumnComboBox.SelectedIndex.ToString & "-Up:" & _ColumnComboBox.Text) <br />
                    End If <br />
<br />
                Case Keys.Enter, Keys.Execute, Keys.Return <br />
                    If _ColumnComboBox.DroppedDown Then <br />
                        _ColumnComboBox.SelectedIndex = _SelectedIndex <br />
                        Debug.WriteLine(_SelectedIndex.ToString & ":*" & _ColumnComboBox.Text) <br />
                        _ColumnComboBox.DroppedDown = False <br />
                        KeyStrokeProcessed = False <br />
                        _ColumnComboBox.Invalidate() <br />
                        _ColumnComboBox.Update() <br />
                        'e.Handled = True <br />
                        Debug.WriteLine(_ColumnComboBox.SelectedIndex.ToString & "ENTER Press 2-New Value:" & _ColumnComboBox.Text) <br />
                    End If <br />
            End Select <br />
            'Dim cbx As NoKeyUpCombo = CType(sender, NoKeyUpCombo) <br />
            'cbx.SelectedIndex = _SelectedIndex <br />
            ' Debug.WriteLine(_ColumnComboBox.SelectedIndex.ToString & "-dgcKeyPress:" & _ColumnComboBox.Text) <br />
            Return <br />
        End If <br />
    End Sub

GeneralListview Pin
Paps223-Nov-04 4:44
Paps223-Nov-04 4:44 
GeneralRe: Listview Pin
Pablo.ar24-Nov-04 3:02
Pablo.ar24-Nov-04 3:02 
GeneralProcesses Pin
cwayman23-Nov-04 3:13
cwayman23-Nov-04 3:13 
GeneralRe: Processes Pin
Carlos Cruz Espino24-Jan-05 11:41
Carlos Cruz Espino24-Jan-05 11:41 
GeneralHTTP Upload Pin
Purple Monk23-Nov-04 2:46
Purple Monk23-Nov-04 2:46 
GeneralConvert to Date Pin
nitin_ion23-Nov-04 2:37
nitin_ion23-Nov-04 2:37 
GeneralRe: Convert to Date Pin
Dave Kreskowiak23-Nov-04 3:04
mveDave Kreskowiak23-Nov-04 3:04 
GeneralRe: Convert to Date Pin
nitin_ion23-Nov-04 4:56
nitin_ion23-Nov-04 4:56 
GeneralRe: Convert to Date Pin
cwayman23-Nov-04 5:30
cwayman23-Nov-04 5:30 
GeneralRe: Convert to Date Pin
Dave Kreskowiak23-Nov-04 6:31
mveDave Kreskowiak23-Nov-04 6:31 
GeneralBest way in getting reading from joystick in VBNet Pin
l03001022-Nov-04 19:23
l03001022-Nov-04 19:23 
GeneralRe: Best way in getting reading from joystick in VBNet Pin
Dave Kreskowiak23-Nov-04 0:46
mveDave Kreskowiak23-Nov-04 0:46 
GeneralFill Labels with SQL Search Results .Net Pin
jlawren722-Nov-04 15:57
jlawren722-Nov-04 15:57 
GeneralHighlighting a Row in a Datagrid Pin
tech@untouchable22-Nov-04 14:22
tech@untouchable22-Nov-04 14:22 
GeneralImplementing Permissions Over Remoting Pin
Paebbels22-Nov-04 11:18
Paebbels22-Nov-04 11:18 
GeneralDeployment Project questions Pin
KreativeKai22-Nov-04 8:58
professionalKreativeKai22-Nov-04 8:58 
GeneralCalling a &quot;Final&quot; routine when application is ended by machine closing. Pin
HollenG22-Nov-04 7:32
HollenG22-Nov-04 7:32 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.