Create ‘Find’ Form With Visual Basic 2005 and .NET Win Forms BindingSource Class

The BindingSource class, new in .NET 2.0, includes a Find method which can be used to get the index of an item in a list with a specified property name and value. Screen Shot

Sample Code


Private Sub FindByLastNameButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles FindByLastNameButton.Click

    ‘ Get the index number of the row in the BindingSource where the value of the

    ‘   LastName column = the value entered into the FindByLastName TextBox on this form.

    Dim indexNumber As Integer = Me.EmployeesBindingSource.Find(“LastName”, Me.FindByLastNameTextBox.Text)

    ‘ Position the binding source on the row.

    Me.EmployeesBindingSource.Position = indexNumber

End Sub

~ bởi duriangroup trên Tháng Sáu 1, 2007.

%d bloggers like this: