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

Incorrect CurrentRow selected after setting the DataSource in a sorted gridview

3 Answers 191 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Victor
Top achievements
Rank 1
Victor asked on 06 Jan 2016, 03:47 PM

When the datasource is set for a gridview with sorting applied, the first row in the Rows collection is selected rather than the first row in the ChildRows collection. This causes the gridview to scroll to the position of the first row in the datasource rather than the first displayed row in the gridview.

 

 Steps to reproduce:

Set the datasource for the gridview

Sort the gridview

Set the datasource for the gridview again

The first row in the datasource will be selected and scrolled to, rather than the first displayed row.

3 Answers, 1 is accepted

Sort by
0
Dess | Tech Support Engineer, Principal
Telerik team
answered on 07 Jan 2016, 09:30 AM
Hello Victor,

Thank you for writing.

When you reset the RadGridView.DataSource in a sorted grid, it is necessary to set the CurrentRow to the desired value. Otherwise, you will obtain the last selected row and the grid will scroll to this row: 
private void radButton1_Click(object sender, EventArgs e)
{
    this.radGridView1.DataSource = null;
    this.radGridView1.DataSource = this.productsBindingSource;
    this.radGridView1.CurrentRow = this.radGridView1.ChildRows[0];
}

I hope this information helps. Should you have further questions I would be glad to help.
 
Regards,
Dess
Telerik
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 Feedback Portal and vote to affect the priority of the items
0
Victor
Top achievements
Rank 1
answered on 07 Jan 2016, 01:27 PM
Is it possible to prevent redundant event firing using this method?
0
Dess | Tech Support Engineer, Principal
Telerik team
answered on 08 Jan 2016, 08:24 AM
Hello Victor,

Thank you for writing back. 

I suppose that you want to prevent the CurrentRowChanged event from firing when using the provided code snippet from my previous post. In order to achieve it, you should unsubscribe from the event before setting the CurrentRow property and subscribe to it again afterwards:
this.radGridView1.CurrentRowChanged -= radGridView1_CurrentRowChanged;
this.radGridView1.CurrentRow = this.radGridView1.ChildRows[0];
this.radGridView1.CurrentRowChanged += radGridView1_CurrentRowChanged;

If it is not the exact event, please specify in details what redundant event firing you want to prevent.

I hope this information helps. If you have any additional questions, please let me know.

Regards,
Dess
Telerik
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 Feedback Portal and vote to affect the priority of the items
Tags
GridView
Asked by
Victor
Top achievements
Rank 1
Answers by
Dess | Tech Support Engineer, Principal
Telerik team
Victor
Top achievements
Rank 1
Share this question
or