Select First Row

10 posts, 0 answers
  1. Xavier Soares
    Xavier Soares avatar
    39 posts
    Member since:
    Jun 2008

    Posted 12 Jun 2008 Link to this post

    Hello,

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

    Thank You.
    LM
  2. Nikolay
    Admin
    Nikolay avatar
    1805 posts

    Posted 13 Jun 2008 Link to this post

    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
  3. Marco
    Marco avatar
    104 posts
    Member since:
    Apr 2011

    Posted 04 Dec 2014 Link to this post

    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 ?

  4. Stefan
    Admin
    Stefan avatar
    2911 posts

    Posted 05 Dec 2014 Link to this post

    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.

     
  5. Marco
    Marco avatar
    104 posts
    Member since:
    Apr 2011

    Posted 05 Dec 2014 in reply to Stefan Link to this post

    Thanks for this explanation Stefan.
  6. Yaroslav
    Yaroslav avatar
    3 posts
    Member since:
    Nov 2016

    Posted 29 Jan Link to this post

    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;

  7. Nadya
    Admin
    Nadya avatar
    503 posts

    Posted 29 Jan Link to this post

    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/.

  8. Yaroslav
    Yaroslav avatar
    3 posts
    Member since:
    Nov 2016

    Posted 29 Jan in reply to Nadya Link to this post

     

    No - for my need need default NULL!

  9. Yaroslav
    Yaroslav avatar
    3 posts
    Member since:
    Nov 2016

    Posted 29 Jan in reply to Yaroslav Link to this post

    After - DataBindingComplete

    GridView - set First row

    "this is complete nonsense"

  10. Nadya
    Admin
    Nadya avatar
    503 posts

    Posted 03 Feb Link to this post

    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/.

Back to Top