How do you search for a value in the first column of a DataGrid?
For example, the first Column of my DataGrid is Called InspectionID. It's a hidden Column.
Lets say the InspectionID is 50, I wish to search or scan or interogate the first Column called InspectionID to find which ROW has the value of InspectionID = 50.
Then I need to make the DataGrid select that row.
Keep in mind that the DataGrid may have 1, 5 or 50 rows of data. |
| CSDeveloper Monday, November 14, 2005 10:02 AM |
Develop a table in SqlServer. Set the primarykey (composite/multicomuln). Then in your project add DataSet.xsd file. Drag your table in the DataSet.xsd file.
Then fill the dataset using the dataadapter.
In your form use Typed dataset you have developed. There you will find a Method (Like if you have two Column IID1 and IID2 as your Primary key then the method name will be
FindByIID1IID2()
) to select that row.
Regards |
| Bappi Monday, March 13, 2006 6:50 AM |
You will need to delegate the search to the DataGrid data source.
For instance, if the dataGrid is bound to a BindingSource that supports searching ( ie, if BindingSource::SupportsSearching == true ) then you can use the BindingSource::Find(string name, object key) method. In this context, 'name' is the name of the column you want to search in ( in your case, the first column ).
If your data grid is not bound to a BindingSource, consider wrapping DataGrid's dataSource inside a BindingSource and then using the BIndingSource's Find capabilities.
For instance, if your code right now is this: dataGrid.DataSource = dataSet11; dataGrid.DataMember = "Customers";
consider changing your code to
BindingSource bindingSource = new BindingSource(); bindingSource.DataSource = dataSet11; bindingSource.DataMember = "Customers"; dataGrid.DataSource = bindingSource;
Hope this helps!
|
| Daniel Herling - Student Monday, November 14, 2005 11:09 PM |
What if I have to search in several columns at the same time?
For example: I have a multiple key in my table (say: the first 3 coumns of the grid) and want to search fo a specific record (row) based on that multiple key.
(As I understand the Find function seems to work with only one 'column' and returns the first occurrence of a row with that value. )
Thanks |
| a_LS Saturday, February 11, 2006 10:29 AM |
Hey does anyone know how to select a row in a table with the primary key consisting of multiple columns?
Thanks
Pascal |
| phaazebroek Tuesday, March 07, 2006 9:40 PM |
Develop a table in SqlServer. Set the primarykey (composite/multicomuln). Then in your project add DataSet.xsd file. Drag your table in the DataSet.xsd file.
Then fill the dataset using the dataadapter.
In your form use Typed dataset you have developed. There you will find a Method (Like if you have two Column IID1 and IID2 as your Primary key then the method name will be
FindByIID1IID2()
) to select that row.
Regards |
| Bappi Monday, March 13, 2006 6:50 AM |
This is great stuff, I've search a lot for this. But still have a problem:
- The FindByxxxxx returns the row. But I need to set the finded row as the current one on my form. Any tips on how to do this?
(I tryied to find an index property on the FindBy returned row, it would allow me to set the Bindingsource.position to that index..... but no property shows that index)
Thanks
|
| a_LS Saturday, March 18, 2006 12:34 PM |
Couldn't you just iterate through the columns like this :
foreach(DataGridViewCell cell in dgv.Columns[colToSearch].Cells) { if (cell.Value == xxx) { do something } }
|
| nsinghal Sunday, March 19, 2006 5:13 AM |
I could iterate, but supose I have 100,000 rows....... it would be extremely ineficient, and very flashy too!
|
| a_LS Thursday, March 30, 2006 2:46 PM |
I could iterate, but supose I have 100,000 rows....... it would be extremely ineficient, and very flashy too!
Microsoft guys, please help with this question. I have a bindingsource that works fine with a single column key, but with a composite key it´s imposible to locate the right row in the datagridview, with a datasource.datatable or with a datasource.dataview.... Please, How can we use bindingsource.find, with composite columns?? Please... answer one.... |
| Rebeca65 Tuesday, August 18, 2009 7:12 PM |