Connecting Tech Pros Worldwide Help | Site Map

Filtering Records in the datagridview

Newbie
 
Join Date: Mar 2009
Posts: 6
#1: Mar 24 '09
I am using Vb.net2005. I have a datagridview which displays some data. I want to filter the records based on some criteria given by the user at runtime. How can I do this. Please Help.

Thanks in Advance
Newbie
 
Join Date: Mar 2009
Posts: 6
#2: Mar 24 '09

re: Filtering Records in the datagridview


Quote:

Originally Posted by BabliS1 View Post

I am using Vb.net2005.

I have a datagridview which displays some data. I want to filter the records based on some criteria given by the user at runtime.The form also contains a combobox.

The datagridview has a column which contains some string seperated by commas. Example:hello,hai

When the user selects an item from the combobox I want the datagridview to search the column data seperated by commas and display only those rows that includes the the specified string.
Currently I am using the Dataview to filter the records. But I dont understand how to search for a specified data within a string.

Could anyone please help me to filter the records in the dataview.

Thanks in Advance.
PRR PRR is offline
Moderator
 
Join Date: Dec 2007
Location: India
Posts: 699
#3: Mar 24 '09

re: Filtering Records in the datagridview


You can use datatable.Select method ....
Expand|Select|Wrap|Line Numbers
  1. string filterExp = "Status = 'Active'";
  2. string sortExp = "City";
  3. DataRow[] drarray;
  4. drarray = dataSet1.Customers.Select(filterExp, sortExp, DataViewRowState.CurrentRows);
  5. // clear your datatable
  6. for (int i=0; i < drarray.Length; i++)
  7. {
  8.    //add rows to datatable 
  9. }
  10. // bind here
  11.  
Newbie
 
Join Date: Mar 2009
Posts: 6
#4: Mar 24 '09

re: Filtering Records in the datagridview


Thanks DeepBlue for your suggestion. But the problem is not solved.
Is it possible to use the split fuction with the RowFilter method.
If yes could you please tell me how.
Member
 
Join Date: Mar 2009
Location: Kathmandu
Posts: 42
#5: Mar 24 '09

re: Filtering Records in the datagridview


dataview.RowFilter = "columnname like '%" & combobox1.Text & "'%"
Newbie
 
Join Date: Mar 2009
Posts: 6
#6: Mar 24 '09

re: Filtering Records in the datagridview


Quote:

Originally Posted by aryanbs View Post

dataview.RowFilter = "columnname like '%" & combobox1.Text & "'%"

But the above line will check if the cell value starts with the specified text.I guess I was not clear in explaining my question.

My form contains a datagridview which is filled during the runtime based on some query. The form also contains a combobox whose items are some words.
The DataGridView(DGV) contains a column whose values are different words(only the ones contained in the datagridview) seperated by commas(Each row has different combination of words)
Now when the user selects a word from the combo I want the datagridview to display only those rows wherein the values for that cell contains the selected word.

Is it possible to split the contents of each cell with "," as the seperator and then compared each word with the selected word and display only that row that satisfies the condition and remove other rows.Currently I am using DataView to filter the records but I dont understand how to split the contents of the cell and compare it with the selected word.

Hope you understand what I meant
Please Help
Reply