Select DataTable Row from datagrid

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
 
C

Cor Ligthert

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
 
G

Guest

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
 

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