G
Gerry Viator
Hi all,
I'm trying to do keyboard events and having some problems.
I'm basically switching between two listbox controls. I want to use tab key
to move selected item down and the ctrl key to move up in the list boxes. I
also want
to move from one control to the other with the right and left arrow keys.
Ok, I'm close to this all working:
I start up in the left listbox and the keys work good, when I press the
right arrow the ctrl key doesn't work
in that listbox but, still the selected item is moving in the first listbox?
I have notice the both controls still
have the focus = true? not sure I understand that(I thought when you set one
control to focus the other one looses it's focus).
I do set all tabstops = false when I first load the program so I can
capture the tab event.
***********************************
Dim ctrl As Control
Dim subctrl As Control
Dim subsubctrl As Control
For Each ctrl In Me.Controls
ctrl.TabStop = False
For Each subctrl In ctrl.Controls
subctrl.TabStop = False
For Each subsubctrl In subctrl.Controls
subsubctrl.TabStop = False
Next subsubctrl
Next subctrl
Next ctrl
*************************************
Friend Sub MainListbox_KeyDown(ByVal sender As Object, ByVal e As
System.Windows.Forms.KeyEventArgs) Handles MainListbox.KeyDown,
ListEntries.KeyDown
If e.KeyCode = Keys.Tab Then
If MainListbox.Focus = True Then
If MainListbox.SelectedIndex < MainListbox.Items.Count - 1
Then
MainListbox.SetSelected(MainListbox.SelectedIndex + 1,
True)
End If
ElseIf ListEntries.Focus = True Then
If ListEntries.SelectedIndex < ListEntries.Items.Count - 1
Then
ListEntries.SetSelected(ListEntries.SelectedIndex + 1,
True)
End If
End If
ElseIf e.KeyCode = Keys.ControlKey Then
If MainListbox.SelectedIndex <> 0 Then
MainListbox.SetSelected(MainListbox.SelectedIndex - 1, True)
Else
If txtmrn.Visible = True Then
MainListbox.SetSelected(0, False)
txtmrn.Select()
End If
End If
ElseIf e.KeyCode = Keys.Left Then
e.Handled = True
ListEntries.SetSelected(0, False)
MainListbox.Focus()
ElseIf e.KeyCode = Keys.Right Then
e.Handled = True
If GroupSublist.Visible = True Then
'Just set the first item.
If ListEntries.Items.Count <> Nothing Then
ListEntries.SetSelected(0, True)
ListEntries.Focus()
End If
End If
End If
End Sub
Thanks for any help
Gerry
I'm trying to do keyboard events and having some problems.
I'm basically switching between two listbox controls. I want to use tab key
to move selected item down and the ctrl key to move up in the list boxes. I
also want
to move from one control to the other with the right and left arrow keys.
Ok, I'm close to this all working:
I start up in the left listbox and the keys work good, when I press the
right arrow the ctrl key doesn't work
in that listbox but, still the selected item is moving in the first listbox?
I have notice the both controls still
have the focus = true? not sure I understand that(I thought when you set one
control to focus the other one looses it's focus).
I do set all tabstops = false when I first load the program so I can
capture the tab event.
***********************************
Dim ctrl As Control
Dim subctrl As Control
Dim subsubctrl As Control
For Each ctrl In Me.Controls
ctrl.TabStop = False
For Each subctrl In ctrl.Controls
subctrl.TabStop = False
For Each subsubctrl In subctrl.Controls
subsubctrl.TabStop = False
Next subsubctrl
Next subctrl
Next ctrl
*************************************
Friend Sub MainListbox_KeyDown(ByVal sender As Object, ByVal e As
System.Windows.Forms.KeyEventArgs) Handles MainListbox.KeyDown,
ListEntries.KeyDown
If e.KeyCode = Keys.Tab Then
If MainListbox.Focus = True Then
If MainListbox.SelectedIndex < MainListbox.Items.Count - 1
Then
MainListbox.SetSelected(MainListbox.SelectedIndex + 1,
True)
End If
ElseIf ListEntries.Focus = True Then
If ListEntries.SelectedIndex < ListEntries.Items.Count - 1
Then
ListEntries.SetSelected(ListEntries.SelectedIndex + 1,
True)
End If
End If
ElseIf e.KeyCode = Keys.ControlKey Then
If MainListbox.SelectedIndex <> 0 Then
MainListbox.SetSelected(MainListbox.SelectedIndex - 1, True)
Else
If txtmrn.Visible = True Then
MainListbox.SetSelected(0, False)
txtmrn.Select()
End If
End If
ElseIf e.KeyCode = Keys.Left Then
e.Handled = True
ListEntries.SetSelected(0, False)
MainListbox.Focus()
ElseIf e.KeyCode = Keys.Right Then
e.Handled = True
If GroupSublist.Visible = True Then
'Just set the first item.
If ListEntries.Items.Count <> Nothing Then
ListEntries.SetSelected(0, True)
ListEntries.Focus()
End If
End If
End If
End Sub
Thanks for any help
Gerry