How to select known DataRow from underlying DataTable on DataGrid (WinForms)

B

Bajgon

Hello,

I have got a DataGrid and a DataTable, which is its DataSource.

I can use DataTable.Rows.Find(key_value) method to locate any row
in the DataTable, using values of key column. The result is a DataRow
object.

How to find and select the current position of this DataRow in
the DataGrid control?

I can use the DataTable.DefaultView.Find(key_value) method,
but there are some restrictions:

1. The key column must be present on the View - I'd rather
have it hidden.

2. The DataGrid needs to be sorted by the key column - I'd rather
not to change the sort order.

3. If the keys are not unique, the method returns first available,
which is not the best idea at all.

So, finding the DataRow on the underlying DataTable is nicer, but
how to map the row back onto the DataGrid?
 
G

Guest

You may want to override the default columns and include the unique key
column in the datagrid. You can set the column width of the unique column to
0 which "hides" the column but makes it now searchable and you can then
highlight the row to the user when you find the row object.

There is a great resource at
http://www.syncfusion.com/FAQ/WinForms/default.asp#44

I have used this a my bible on the datagrid.

Cheers!

Rob
 
B

Bajgon

You may want to override the default columns and include the unique key
column in the datagrid. You can set the column width of the unique column
to
0 which "hides" the column but makes it now searchable and you can then
highlight the row to the user when you find the row object.

Thanks,

But this method still does not solve the problem, that the grid needs
to be sorted by the key column for the Find method to work.
I could try resorting but it will loose the selection (sic!).
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top