Select First Row

5 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
    1803 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. UI for WinForms is Visual Studio 2017 Ready
  4. Marco
    Marco avatar
    87 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 ?

  5. Stefan
    Admin
    Stefan avatar
    2891 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.

     
  6. Marco
    Marco avatar
    87 posts
    Member since:
    Apr 2011

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

    Thanks for this explanation Stefan.
Back to Top
UI for WinForms is Visual Studio 2017 Ready