Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Filtering data in datagrid

Status
Not open for further replies.

RocAFella2007

Technical User
Mar 21, 2007
45
GB
Hi, I was hoping somebody could offer me some help please. I have a datagrid and I want to filter the data, I know hwo to do this but the method I know is a different way. The way I do this is by typing some letters in a textbox which filters the datagrid, however the method I want to do it by is when the form loads there is already text in the textbox and I want to filter it automatically.

I have used the following coding:

Dim dvfilter As DataView = Nothing
If TypeOf dgitemreturn.DataSource Is DataView Then
dvfilter = CType(dgitemreturn.DataSource, _
DataView)
ElseIf TypeOf dgitemreturn.DataSource Is DataTable Then
dvfilter = CType(dgitemreturn.DataSource, _
DataTable).DefaultView
End If

If txtitems.TextLength > 0 Then
dvfilter.RowFilter = String.Format("ItemsTaken LIKE '{0}*' ", _
txtitems.Text)
Else
dvfilter.RowFilter = ""
End If
dgitemreturn.DataSource = dvfilter

I have tried the above in teh form load event, textbox changed even but its still not working. However when I remove the text from the textbox and then run the program it works. Any help please?
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top