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

How to stop auto select of first record/selection changed event

3 Answers 81 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Andrew
Top achievements
Rank 1
Andrew asked on 10 Mar 2011, 12:07 AM
Hi,

The behaviour I am trying to stop is this,

I have a gridview that is used as a generic list/grid that is populated by different data based on a users selections.

I have a function that is called whenever the selection changed event is fired.

My problem is the selection changed event is fired whenever the grid is populated with data, therefore can I stop the autoselection
of the first record whenever the grid is populated.

NB I am using the latest version of the gridview 2010 Q3 (2010.3 10.1215)

Thanks for any help

Andrew

3 Answers, 1 is accepted

Sort by
0
Emanuel Varga
Top achievements
Rank 1
answered on 10 Mar 2011, 07:28 AM
Hello Andrew,

In order to deselect all rows after data binding the grid, you can register for the DataBindingComplete event and clear the selection there. But there is a catch, because of the asynchronous nature of the grid you should use a timer to call a clear selection on the grid, like so:
void radGridView1_DataBindingComplete(object sender, GridViewBindingCompleteEventArgs e)
{
    var timer = new Timer();
    timer.Interval = 20;
    timer.Tick += delegate
    {
        timer.Stop();
        radGridView1.ClearSelection();
        radGridView1.CurrentRow = null;
    };
 
    timer.Start();
}

Hope this helps, if you have any other questions or comments, please let me know,

Best Regards,
Emanuel Varga
Telerik WinForms MVP
0
Richard Slade
Top achievements
Rank 2
answered on 10 Mar 2011, 10:19 AM
Hello Andrew,

To add to Emanuel's suggestions, you could also remove the event handler for the event before binding, and re-add the handler after binding to ensure that the event is not fired.
Regards,
Richard
0
Andrew
Top achievements
Rank 1
answered on 11 Mar 2011, 01:49 AM
Thank you guys for your help.

It was as I feared, there is no property in the winforms grid (unlike the silverlight version) which performed this function.

I ended up using a "flag" when the data source was changed and my controls leave/load events to ignore the initial row selection.

Thanks again for all the assistance

Andrew

Tags
GridView
Asked by
Andrew
Top achievements
Rank 1
Answers by
Emanuel Varga
Top achievements
Rank 1
Richard Slade
Top achievements
Rank 2
Andrew
Top achievements
Rank 1
Share this question
or