character string matches a speified patern(LIKE 'c%' )in DataView.

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

If any one has idea how to search Datatabke/dataview like "LIKE in sql" by
using Dataview.Find method or any other way, can you please let me know

Thanks
 
you can use the DataView.RowFilter which will filter out rows based on the
expression.

Dataview1.RowFilter = "Name LIKE 'Tech%'"

hope that helps..
Imran.
 
Or you can use Select method.

Regards,
Grzegorz

U¿ytkownik "Imran Koradia said:
you can use the DataView.RowFilter which will filter out rows based on the
expression.

Dataview1.RowFilter = "Name LIKE 'Tech%'"

hope that helps..
Imran.
 
Thanks for the replies.

I need to find the row number in the dataview so that i can move the cursor
in the grid to that row(Note: I am binding datatable/dataview to a grid).


Thanks
 
Hi,

It is not reliable way, because order in a grid could be different from what
you have in a DataView. Best way is to find row in a dataview, get its
primary key field(s), which uniquely identifies row
 
Thanks for the reply. I am trying to implement the "search/Find" in Datagrid.
I am binding the grid with dataview using Currency manager. which seems to
work fine. after sorting also both Grid and dataview seems to be in sync.

as you said once i get the primary key, how can i point the cursor in the
grid to the correct row?


Thanks
 
To set the current row you will have to set CurrencyManager.Position.
To get the index using LIKE I would do:
1. use underlying DataTable.Select to find the row
2. extract pk from the row
3. do a for loop through all DataRowView in DataView and compare the pk you
got in point 2.
4. When you find the matching row you'll have also its index
5. use index to set CurrencyManager.Position
 
Thanks Miha, It works.
Thanks every one for your replies

Miha Markic said:
To set the current row you will have to set CurrencyManager.Position.
To get the index using LIKE I would do:
1. use underlying DataTable.Select to find the row
2. extract pk from the row
3. do a for loop through all DataRowView in DataView and compare the pk you
got in point 2.
4. When you find the matching row you'll have also its index
5. use index to set CurrencyManager.Position

--
Miha Markic [MVP C#] - RightHand .NET consulting & development
miha at rthand com
www.rthand.com

Techstudent said:
Thanks for the reply. I am trying to implement the "search/Find" in
Datagrid.
I am binding the grid with dataview using Currency manager. which seems to
work fine. after sorting also both Grid and dataview seems to be in sync.

as you said once i get the primary key, how can i point the cursor in the
grid to the correct row?


Thanks
 
Try This.

DataView1 is a dataview filled with data
txtSearch is the textbox containing string to search for
DataGrid1 is the datagrid to which the DataView1 is attached

DataView1.Sort="FieldName";
//"FieldName" is the field in which the search will take place
int i=DataView1.Find(cmbSearch.Text);
if(i>DataView1.Table.Rows.Count || i<0)
{
MessageBox.Show("Record Not Found.");
}
else
{
DataGrid1.CurrentCell=new DataGridCell(i,1) ;
}
 
Back
Top