954,551 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

Filtering a DataGridView

Visual Basic.Net:

I have a DataGridView in Last Name sequence.
Is it possible to when a user types the first letter of a last name
that it displays all rows with last names that start with that letter.
When he types the second letter, it displays all records whose last name starts with those 2 letters, etc.?

furjaw
Newbie Poster
23 posts since Mar 2006
Reputation Points: 10
Solved Threads: 0
 

This is pretty much doable and this functionality is called AutoComplete is Web Platform and Incremental Search in WinForms Arena.

binoj_daniel
Practically a Master Poster
645 posts since Dec 2006
Reputation Points: 25
Solved Threads: 18
 

It works great!!!
Below is the code that I ended up with:

If LastNameTextBox.TextLength > 0 Then
PatientBindingSource.Filter = String.Format("LastName Like '" & LastNameTextBox.Text) & "*'"
Else
PatientBindingSource.Filter = String.Empty
End If

furjaw
Newbie Poster
23 posts since Mar 2006
Reputation Points: 10
Solved Threads: 0
 

What event of the textbox did you use?

binoj_daniel
Practically a Master Poster
645 posts since Dec 2006
Reputation Points: 25
Solved Threads: 18
 

Private Sub LastNameTextBox_TextChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles LastNameTextBox.TextChanged

furjaw
Newbie Poster
23 posts since Mar 2006
Reputation Points: 10
Solved Threads: 0
 

Thats good, glad you solved it. you can read more .net articles & best professional best practices here

binoj_daniel
Practically a Master Poster
645 posts since Dec 2006
Reputation Points: 25
Solved Threads: 18
 

Hi guys, there is an example of code posted of exactly that you want to do (it evens uses the First Name field and does "on the fly data filtering" based on filter condition)

You may see it in action here:

Dynamic filtering DataGridView in C#
http://www.dotneat.net/2008/12/03/DynamicDataGridViewFilteringInC.aspx

(Windows Forms and C#)

iloire
Newbie Poster
1 post since Dec 2008
Reputation Points: 10
Solved Threads: 0
 

hi, there.. i try used your code, but it doesn't help...


If LastNameTextBox.TextLength > 0 Then
PatientBindingSource.Filter = String.Format(

iedapRo
Newbie Poster
1 post since Mar 2010
Reputation Points: 10
Solved Threads: 0
 

Hi iedapRo.

This thread is almost three yeard old. If you want to ask question, start your own (new) thread. Please read daniweb member ru le and http://www.daniweb.com/forums/thread78223.html

Thread Closed.

__avd
Posting Genius (adatapost)
Moderator
8,648 posts since Oct 2008
Reputation Points: 2,136
Solved Threads: 1,241
 

This question has already been solved

Post: Markdown Syntax: Formatting Help
You