1

My form allows the user to search a collection of customers. When I click on the Search button I want it to display only the specific result that was found and hide the rest of the customers.

For example, if I put customer id as 133 it should only show that one and hide the rest.

Private Sub SearchButton_Click(sender As Object, e As EventArgs) Handles SearchButton.Click
    Dim foundIndex As Integer
    Dim searchString As String
    searchString = SearchTextBox.Text
    foundIndex = CustomerRecBindingSource.Find("customerid", searchString)
    If foundIndex > -1 Then
        DataRepeater1.CurrentItemIndex = foundIndex
    Else
        MsgBox("Item " & searchString & " not found.")
    End If
End Sub

This version only brings the search results to the top. It doesn't hide the rest of the data.

I tried changing the line:

DataRepeater1.CurrentItemIndex = foundIndex

to

DataRepeater1.CurrentItem = foundIndex

but then I get the error Property 'Current Item' is 'Read Only'

Peter G
  • 2,773
  • 3
  • 25
  • 35
Rick Cresci
  • 81
  • 1
  • 1
  • 6
  • I think CurrentItemIndex is the right way to go to highlight the located records. What type of BindingSource are you using? Is there a .Filter property you can set? Something like: CustomerRecBindingSource.Filter = "customerid = '" & searchString & "'" – vbigham Jul 17 '18 at 23:53
  • the data binding source is ms access dataset. I tried filter option it doesn't work. – Rick Cresci Jul 18 '18 at 01:12
  • Hi thank you so much the .filter worked like a charm after I changed foundIndex from integer to string! – Rick Cresci Jul 18 '18 at 01:19
  • Moved problem statement to the top, improved code formatting (check [here](https://stackoverflow.com/editing-help) for help with that), and made some statements clearer. – Peter G Jul 18 '18 at 03:27

0 Answers0