Get the correct DataTable Row?

R

R Agam

Hi

I am using a DataGrid with sorting enabled.
When the user double click on a Row I get the selected index. Now How can I
get the DataTable row corresponding to the selected index?



Thanks,
Ronen
 
N

Nicholas Paldino [.NET/C# MVP]

Ronen,

If you have the row number, you can pass the row number to the DataView
returned by the DefaultView property on the DataTable. This view is what is
being sorted. The indexer for the view will return the items in the correct
order.

Hope this helps.
 
M

MB

Hi R Agam

the only way i found is using BindingManagerBase

exp:
BindingManagerBase bm = MyGrid.BindingContext[MyGrid.DataSource,
MyGrid.DataMember];

string Name = ((DataRowView)bm.Current).Row["Name"].ToString();

Using DefaultView it dosn't work for me (with sorting enabled)

string Name =
Dt.DefaultView.Table.Rows[MyGrid.CurrentRowIndex]["Name"].ToString());
 

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