This is a migrated thread and some comments may be shown as answers.
Select First Row
9 Answers 280 Views
This is a migrated thread and some comments may be shown as answers.
Xavier Soares
Top achievements
Rank 2
Xavier Soares asked on 12 Jun 2008, 06:32 PM
Hello,

How can I make the first row of a RadgridView selected by default, if there's any?

Thank You.
LM

9 Answers, 1 is accepted

Sort by
0
Nikolay
Telerik team
answered on 13 Jun 2008, 04:15 PM
Hi Luis,

Actually, the first row of RadGridView is selected by default. Still, you can use the code below to programmatically select rows:

this.radGridView1.Rows[0].IsSelected = true

Feel free to contact me if you have further questions.

Kind regards,
Nikolay
the Telerik team

Instantly find answers to your questions at the new Telerik Support Center
0
Marco
Top achievements
Rank 2
answered on 04 Dec 2014, 09:59 AM
Sorry for the ressurection of this topic but I need some precision about it.

The first row of a RadGridView is certainly selected by default when the databinding is done.

But if you have set some sort descriptor before (on design as an exemple), it look like the selection of the first row is done before sorting. So the "first selected row" move in a random place if the datasource is not sorted the same way as your descriptor before binding.

I don't think it's a good idea to rely on the fact that your datasource order is the same of the grid because you could be sure that one day somebody will change only one of them and the random selected row effect will come back.

What's the position of Telerik on this behavior ?

0
Stefan
Telerik team
answered on 05 Dec 2014, 02:23 PM
Hello Marco,

RadGridView's CurrentRow will be set to the row according to the form's CurrencyManager's Position property. So, when you assign a DataSource to the grid, the Form's CurrencyManager will know about this source, and its Position defaults to 0. Then, when you sort the grid, this Position (and the grid's CurrentRow) is not changed, which is desired and expected.

However, you can easily change the CurrentRow, by simply setting this property of the grid to any of its rows. For example in your case you can use the DataBindingComplete event:
void radGridView1_DataBindingComplete(object sender, GridViewBindingCompleteEventArgs e)
{
    radGridView1.CurrentRow = radGridView1.Rows[radGridView1.Rows.Count - 1];
}

I hope that you find this information useful. Should you have any other questions, do not hesitate to contact us.

Regards,
Stefan
Telerik
 

Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.

 
0
Marco
Top achievements
Rank 2
answered on 05 Dec 2014, 02:34 PM
Thanks for this explanation Stefan.
0
Yaroslav
Top achievements
Rank 1
answered on 29 Jan 2021, 08:26 AM

Hello

 

How set NULL row by default on DataBinding?

 

P/S

found only one option

 private void MasterTemplate_CurrentRowChanged(object sender, CurrentRowChangedEventArgs e)
        {
            if (this.dataSourceChanging)
                return;

0
Nadya
Telerik team
answered on 29 Jan 2021, 01:07 PM

Hello, Yaroslav,

If you do not want to have a current row, you could set the CurrentRow property to null just after binding the grid:

this.radGridView1.CurrentRow = null;

I hope this helps. If you have other questions please let me know.

Regards,
Nadya
Progress Telerik

Virtual Classroom, the free self-paced technical training that gets you up to speed with Telerik and Kendo UI products quickly just got a fresh new look + new and improved content including a brand new Blazor course! Check it out at https://learn.telerik.com/.

0
Yaroslav
Top achievements
Rank 1
answered on 29 Jan 2021, 04:39 PM

 

No - for my need need default NULL!

0
Yaroslav
Top achievements
Rank 1
answered on 29 Jan 2021, 04:49 PM

After - DataBindingComplete

GridView - set First row

"this is complete nonsense"

0
Nadya
Telerik team
answered on 03 Feb 2021, 10:03 AM

Hello, Yaroslav,

If I understand you correctly you don't want the current row to change. In order to prevent the current row from changing you can use the CurrentRowChanging event that fires right before the current row is about to change and cancel it:

this.radGridView1.CurrentRowChanging += this.RadGridView1_CurrentRowChanging;
private void RadGridView1_CurrentRowChanging(object sender, CurrentRowChangingEventArgs e)
{
   e.Cancel = true;
}

Let me know if you have other questions. 

Regards,
Nadya
Progress Telerik

Virtual Classroom, the free self-paced technical training that gets you up to speed with Telerik and Kendo UI products quickly just got a fresh new look + new and improved content including a brand new Blazor course! Check it out at https://learn.telerik.com/.

Asked by
Xavier Soares
Top achievements
Rank 2
Answers by
Nikolay
Telerik team
Marco
Top achievements
Rank 2
Stefan
Telerik team
Yaroslav
Top achievements
Rank 1
Nadya
Telerik team
Share this question
or