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 gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Determining associated DataTable Row with selected DataView row

Status
Not open for further replies.

StevenK

Programmer
Jan 5, 2001
1,294
GB
I’m having some trouble making use of a DataView within a grid. I can step through all the cells in the selected grid row using something like dataGrid[0, 1].ToString(), similarly I can step through all the rows in the DataView (the DataView is set as the DataSource for the dataGrid) using the syntax dataView1[0][1].ToString(). The problem I have is determining how to obtain a hold on the associated DataRow in the underlying DataTable (as set by dataView1.Table = dataTable1 for instance). Do I need to perform something like a Find() against the primary key fields for DataTable / DataView ?
Or is there some more direct and simple way of determining the associated row in the underlying DataTable ?
If I have run a different Sort against the DataView in the dataGrid the row index will not be the same between the DataView (on show) and the DataTable. How can I quickly get a link to this row ?
Any help would be appreciated.
Thanks in advance.
Steve
 
The way I see it, the only thing you can base on is the primary key of the data table. Now, it depends what you want to do. If you're making an UPDATE or DELETE on the row, you can do it directly, without bothering for finding the datarow inside the datatable. You can use UPDATE ... WHERE Key = value or DELETE FROM ... WHERE Key = value.
If you're planning to do something more sophisticated than that, maybe you'll let me know what and I'll suggest you a solution, if I can.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top