This is a migrated thread and some comments may be shown as answers.

Grouping/Sorting changes GridView row number, but not DataSource's

3 Answers 221 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Robert Miles
Top achievements
Rank 1
Robert Miles asked on 06 Apr 2010, 09:40 PM
I've got an app that does the following:

1) Load a DataTable with info
2) Attach the DataTable to the RadGridView
3) Runs a threaded, long process using a BackgroundWorker object.
4) Since it's using a separate thread, I update the rows with new information via the DataTable object using the row number as my identifier to know which row needs updating.

This is all fine until the GridView is grouped. If I group, then run the same process, the row number for the GridView has changed, but not for the DataTable object. How can I get them the same so I know which row to update?

3 Answers, 1 is accepted

Sort by
0
Martin Vasilev
Telerik team
answered on 09 Apr 2010, 01:54 PM
Hello Robert Miles,

Thank you writing.

The described behavior is expected, because all data operations in RadGridView (such as sorting, filtering, grouping etc) lead to rearranging the grid's Rows collection, but not the data source's one.
 
Using the RowIndex is not a good practice, instead just save the reference of the particular row in the GridViewRowInfo object:
 
GridViewRowInfo row = this.radGridView1.CurrentRow;


All the best,
Martin Vasilev
the Telerik team

Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items.
0
Robert Miles
Top achievements
Rank 1
answered on 09 Apr 2010, 02:59 PM
I'm afraid that won't work. I have to update the DataTable object since I am using a BackgroundWorker thread. Since it's a separate thread, I can't do any operations on UI objects that were created in the main thread. I need to know its index in the DataTable.

Any other ideas?
0
Martin Vasilev
Telerik team
answered on 14 Apr 2010, 05:26 PM
Hello Robert Miles,

If you want a direct access to underling row's object, just take the bound datasource's object for the particular row through its DataBoundItem:
 
DataRowView rowView = this.radGridView1.Rows[0].DataBoundItem as DataRowView;
if (rowView != null)
{
    //do something with rowView
}


Kind regards,
Martin Vasilev
the Telerik team

Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items.
Tags
GridView
Asked by
Robert Miles
Top achievements
Rank 1
Answers by
Martin Vasilev
Telerik team
Robert Miles
Top achievements
Rank 1
Share this question
or