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.
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.