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

Finding the Row Index for a DataTable

Status
Not open for further replies.

Headwinds

Programmer
Feb 6, 2001
38
0
0
US
I have a DataGrid on a Windows form bound to a DataTable in a DataSet. The DataTable query retrieves columns including the OrgName and Orgid from a database table Organization. The Orgid is a meaningless sequential number, so the query orders the results by OrgName to help users easily locate an organization in the DataGrid.

I want to allow a user to edit any number of rows in the DataGrid and then click a Submit button. Before updating the data in the database, I’ll perform several checks on the values that were changed, and if illegal data is found, I want to inform the user and reposition the DataGrid to the row in which the error was found.

I can capture the OrgID of the DataTable row in which an error was found. To reposition the DataGrid to that row, I need to know the index of the row in the DataTable. Using the DataTable.Find method returns a row object, which apparently has no method that returns its index in the DataTable. Using a DataView.Find method for the default view returns an index, but it requires that I declare a sort column. If I declare the sort column to be “OrgID,” then the defaultview is not sorted on the same values as the DataTable itself, and the index returned is meaningless. If I declare the sort order to be “OrgName,” I get the proper index returned, but I’m locating by a non-unique value.

Is there some other way of discovering a row index for a DataTable that will get me out of this Catch-22?

Thanks in advance.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top