We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. Image for the cookie policy date

Identify row in grid based on key in database

I have some validation in the business layer of my application. If it fails for a row in the database I will get an exception in the UI layer along with the value of the key for the row in the data that had the problem.

So from the UI I have a GDBG and a string which is the key to the offending row. The key is NOT stored in the grid. I think I need to do the following:

1. Use the key to identify the row in the underlying datalayer.
2. Then find the row in the GDBG for the row in the datalayer.
3. Move focus to that row (I don’t need help with that part)

I am having trouble making this work. Could you please provide an example.

Thank You


3 Replies

JJ Jisha Joy Syncfusion Team June 11, 2009 09:25 AM UTC

Hi Mark,

If you are having record index of the underlying datasource, you could try using the ListManagerPositionToRowIndex method.This is used to find the row index within the grid from the row index within the data source.

this.gridDataBoundGrid1.Binder.ListManagerPositionToRowIndex(index);

Please let me know if this helps.

Regards,
Jisha


MK Mark Kenner June 11, 2009 05:15 PM UTC

Thanks for the reply.

I have tried ListManagerPositionToRowIndex. It worked untill I sorted the grid. After a sort it would still return the same value (where the row in the grid would have been if the grid was not sorted). Am I missing a step?

I can always put the key in the grid and hide it but I think there must be a better way.



RC Rajadurai C Syncfusion Team June 13, 2009 11:27 AM UTC

Hi Mark,

Thanks for your update.

Please try the following code.

CurrencyManager cm = (CurrencyManager)this.BindingContext[this.gridDataBoundGrid1.DataSource, this.gridDataBoundGrid1.DataMember];
int pos = this.gridDataBoundGrid1.Binder.PositionToRowIndex(0);
DataRow dr = ((DataRowView)cm.List[pos]).Row;
Console.WriteLine(dr[0].ToString());

This code retrieves the data value of the first column from the underlying row position. There is no other direct way found to get the position of underlying row after sorting in griddataboundgrid.It has to be handled through some code manually.

Regards,
Rajadurai

Loader.
Live Chat Icon For mobile
Up arrow icon