Select DataTable Row from datagrid

  • Thread starter Thread starter Andrew Mason
  • Start date Start date
A

Andrew Mason

I have a datagrid that is bound to a datatable. I would like to select
the correct row in the datatable when a user clicks on a row in the
datagrid.

I thought that it would look something like this;
Dim drSelectRow As DataRow =
dtProducts.Select(dgProducts.CurrentRowIndex)

But this gives me an error.

MTmace
 
Andrew,

There are a lot of possibilities an easy one is using a dataview as
datasource and than

Roughly typed in this message and not tested so watch typos

\\\
dim dvProducts new dataview(dtProducts)
dgProducts.datasource = dvProducts
///
\\\
Dim dvSelectRow As DataRowView = dvProducts.Rows(dgProducts.CurrentRowIndex)
///
You can use a DataRowView almost the same as a datarow.

The problem is that when you use the datatable direct and the user sorts the
grid, you get the wrong row.

I hope this helps

Cor
 
If you in a Window Application....
then better use a bindingcontext and currencymanager.
If you need sinippets then the VS.net docmn is the best place..

Let us know if it helps...

Cheers,
siaj
 
Back
Top