Link to home
Start Free TrialLog in
Avatar of PeterBaileyUk
PeterBaileyUk

asked on

VB.net listbox. make all searches occur

I have an identical action that needs to occur as in ID: 41772683 but this one uses listboxes. I have made the search boxes at the top populate according to whats typed in the CW column (using the search option bottom right)  but I cannot see how to emulate the enter keypress across the other columns programatically.

here is the first columns key up within this the search occurs

 Private Sub OnKeyUpCW(sender As Object, e As KeyEventArgs) Handles TextSearchCW.KeyUp, ListCW.KeyUp
        Dim index = -1

        If OPTagIndependant.Checked = True Then


        Else

            TextSearchAbi.Text = TextSearchCW.Text
            TextSearchCap.Text = TextSearchCW.Text
            TextSearchGlass.Text = TextSearchCW.Text
            TextSearchTvi.Text = TextSearchCW.Text

        End If

        If TypeOf sender Is TextBox Then
            Dim tb = DirectCast(sender, TextBox)
            If tb.Equals(TextSearchCW) Then
                If e.KeyCode.Equals(Keys.Enter) Then
                    index = ListCW.FindString(tb.Text)
                    If index <> -1 Then
                        ListCW.SetSelected(index, True)
                    End If
                    tb.Clear()
                    e.Handled = True
                End If
            End If
        ElseIf TypeOf sender Is ListBox Then
            Dim lb = DirectCast(sender, ListBox)
            If lb.Equals(ListCW) Then
                If e.KeyCode.Equals(Keys.Enter) Then
                    index = lb.FindString(TextSearchCW.Text)
                    If index <> -1 Then
                        lb.SetSelected(index, True)
                    End If
                    TextSearchCW.Clear()
                    e.Handled = True
                ElseIf e.KeyCode.Equals(Keys.Back) Then
                    If TextSearchCW.Text.Length > 0 Then
                        TextSearchCW.Text = TextSearchCW.Text.Substring(0, TextSearchCW.Text.Length - 1)
                    End If
                Else
                    TextSearchCW.Text = TextSearchCW.Text + Convert.ToChar(e.KeyCode)
                End If
            End If
        End If
    End Sub

Open in new window


Each of the others are within their own key up event.
    Private Sub OnKeyUpAbi(sender As Object, e As KeyEventArgs) Handles TextSearchAbi.KeyUp, ListAbi.KeyUp
        Dim index = -1
        If TypeOf sender Is TextBox Then
            Dim tb = DirectCast(sender, TextBox)
            If tb.Equals(TextSearchAbi) Then
                If e.KeyCode.Equals(Keys.Enter) Then
                    index = ListAbi.FindString(tb.Text)
                    If index <> -1 Then
                        ListAbi.SetSelected(index, True)
                    End If
                    tb.Clear()
                    e.Handled = True
                End If
            End If
        ElseIf TypeOf sender Is ListBox Then
            Dim lb = DirectCast(sender, ListBox)
            If lb.Equals(ListAbi) Then
                If e.KeyCode.Equals(Keys.Enter) Then
                    index = lb.FindString(TextSearchAbi.Text)
                    If index <> -1 Then
                        lb.SetSelected(index, True)
                    End If
                    TextSearchAbi.Clear()
                    e.Handled = True
                ElseIf e.KeyCode.Equals(Keys.Back) Then
                    If TextSearchAbi.Text.Length > 0 Then
                        TextSearchAbi.Text = TextSearchCW.Text.Substring(0, TextSearchAbi.Text.Length - 1)
                    End If
                Else
                    TextSearchAbi.Text = TextSearchAbi.Text + Convert.ToChar(e.KeyCode)
                End If
            End If
        End If
    End Sub

Open in new window

ee.JPG
Avatar of louisfr
louisfr

You could call the OnKeyUpXXX methods and pass the arguments you want.
Avatar of PeterBaileyUk

ASKER

how do i pass an 'enter' to the method. that for sure would do it.
ASKER CERTIFIED SOLUTION
Avatar of louisfr
louisfr

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
thank you