Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to get the row position in dataset from the datagrid 1

Status
Not open for further replies.

mondi

Programmer
Sep 10, 2003
169
AL
I am using Visual Studio .NET 2003. I have created a datagrid in a form, and I have bound it to a datatable of a dataset.
The datagrid at the begginning is sorted by one of the columns. At this point, is not difficult to find in which row of the dataset is found the data grid row that the user selects. But if he sorts the datagrid by another column of the datagrid, how can I find the exact row in dataset that he selects?
Thanks in advance for any help
 
A DataView object allows data binding on both Windows Forms and Web Forms.
Whenever data is displayed only one version of each row is displayed e.g Default, Original, Current, and Proposed. The displayed row is a DataRowView object that represents a customized view of a DataRow from the DataTable.
Let be
DataRowView selRow =...; // The selected row in the DataGrid control
DataRow dr = selRow.Row // Gets the DataRow from being viewed.

-obislavu-





 
Code:
BindingManagerBase bm = dataGrid1.BindingContext(dataGrid1.DataSource, dataGrid1.DataMember);

DataRow dr = ((DataRowView)bm.Current).Row;
 
Thank you for your answers. They were very helpful, especially the answer of SHelton.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top