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

Disable Automatic Row Selection

2 Answers 1459 Views
GridView
This is a migrated thread and some comments may be shown as answers.
zzz
Top achievements
Rank 1
zzz asked on 08 Sep 2011, 03:36 PM
Hello!
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.
Thanks. 

2 Answers, 1 is accepted

Sort by
0
Accepted
Jack
Telerik team
answered on 08 Sep 2011, 04:06 PM
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;
    }
    else
    {
        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.
 
Greetings,
Jack
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 >>

0
Emanuel Varga
Top achievements
Rank 1
answered on 09 Sep 2011, 06:01 AM
Hello,

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

this.radGridView1.ClearSelection();
radGridView1.CurrentRow = null;

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

Best Regards,
Emanuel Varga

WinForms MVP
Tags
GridView
Asked by
zzz
Top achievements
Rank 1
Answers by
Jack
Telerik team
Emanuel Varga
Top achievements
Rank 1
Share this question
or