RocAFella2007
Technical User
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?
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?