Disable Automatic Row Selection

3 posts, 1 answers
  1. zzz
    zzz avatar
    6 posts
    Member since:
    Jul 2011

    Posted 08 Sep 2011 Link to this post

    Is it possible to turn off automatic selection of the first row in a GridView. The automatic selection takes place on grid creation an when rebinding the data source.
  2. Answer
    Jack avatar
    2335 posts

    Posted 08 Sep 2011 Link to this post

    Hello Zzz,

    Thank you for this question. 

    You cannot disable the selection, however you can disable it. To do this you have to handle the CurrentRowChanging event. Please, consider the code snippet below:

    void radGridView1_CurrentRowChanging(object sender, CurrentRowChangingEventArgs e)
        e.Cancel = true;

    Of course you can just reset it after the binding completes:

    void radGridView1_DataBindingComplete(object sender, GridViewBindingCompleteEventArgs e)
        this.radGridView1.CurrentRow = null;

    A third option will be to customize the current row style:

    void radGridView1_CellFormatting(object sender, CellFormattingEventArgs e)
        if (e.CellElement.RowElement.IsCurrent || e.CellElement.RowElement.IsSelected)
            e.CellElement.DrawFill = false;
            e.CellElement.DrawBorder = false;
            e.CellElement.ResetValue(LightVisualElement.DrawFillProperty, ValueResetFlags.Local);
            e.CellElement.ResetValue(LightVisualElement.DrawBorderProperty, ValueResetFlags.Local);

    Should you have any further questions, do not hesitate to ask.
    the Telerik team

    Thank you for being the most amazing .NET community! Your unfailing support is what helps us charge forward! We'd appreciate your vote for Telerik in this year's DevProConnections Awards. We are competing in mind-blowing 20 categories and every vote counts! VOTE for Telerik NOW >>

  3. DevCraft R3 2016 release webinar banner
  4. Emanuel Varga
    Emanuel Varga avatar
    1336 posts
    Member since:
    May 2010

    Posted 09 Sep 2011 Link to this post


    If you just want to deselect the first row, on repopulating the data source, just do the following on the DataBindingComplete event:

    radGridView1.CurrentRow = null;

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

    Best Regards,
    Emanuel Varga

    WinForms MVP
Back to Top