RadGridView Selected Index

12 posts, 0 answers
  1. Stephan
    Stephan avatar
    2 posts
    Member since:
    Apr 2008

    Posted 23 Apr 2008 Link to this post

    Hello,

    How do you get and set the selected index on a RadGridView control.
    There is no such thing as .SelectedIndex on the grid.

    Thanks,
    Stephan
  2. Jack
    Admin
    Jack avatar
    2335 posts

    Posted 23 Apr 2008 Link to this post

    Hi Stephan,

    Thank you for this question.

    You are correct, RadGridView doesn't have a SelectedIndex property. RadGridView presents hierarchical and grouped data. Because of this, using the SelectedIndex property by itself would be misleading.

    In case of flat (nonhierarchical) data, you can use the IndexOf property of the Rows collection of RadGridView. This value will represent the index of the currently selected row in the top-most level of the RadGridView.If you would like to get the index of a row that is nested deeper in the hierarchy, please use the corresponding GridViewTemplate.

    Refer to the following code snippet:

    int selectedIndex = this.radGridView1.Rows.IndexOf(this.radGridView1.CurrentRow); 

    I hope this helps. Do not hesitate to write, if you have further questions.

    All the best,
    Jack
    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. sculver
    sculver avatar
    3 posts
    Member since:
    Aug 2006

    Posted 27 Aug 2008 Link to this post

    I too needed to get the index of the selected (or current) row for non-heirarchtical sets, and I tried what you mentioned, but it does not compile:

    I am using VS 2008, and running the latest version (as of yesterday) of the telerik controls.

    Here is the error:
    Error 2 Argument '1': cannot convert from 'Telerik.WinControls.UI.GridViewRowInfo' to 'Telerik.WinControls.UI.GridViewDataRowInfo' C:\Source\WebPortal\Developers\sculver\EnhancedAttachmentControl\EnhancedAttachmentControl\EnhancedAttachmentControl.cs 210 55 EnhancedAttachmentControl


    It seems that the indexof method expects a DataRowInfo and the CurrentRow is only a RowInfo type.

    Is there some other method to accomplish this without iterating through the list?
  5. Martin Vasilev
    Admin
    Martin Vasilev avatar
    1061 posts

    Posted 29 Aug 2008 Link to this post

    Hello sculver,

    Thank you for writing.

    You have to cast the current row to GridViewDataRowInfo. Please, review the code-block below as a reference:
     
    if (this.radGridView1.CurrentRow is GridViewDataRowInfo) 
        int selectedIndex =  
            this.radGridView1.Rows.IndexOf((GridViewDataRowInfo)this.radGridView1.CurrentRow); 

    I hope this helps. If you have other questions, do not hesitate to contact me again.

     
    Sincerely yours,
    Martin Vasilev
    the Telerik team

    Check out Telerik Trainer, the state of the art learning tool for Telerik products.
  6. Fernando
    Fernando avatar
    13 posts
    Member since:
    Sep 2010

    Posted 10 Sep 2010 Link to this post

    Excelent!! Thank you!
  7. Frederico Fernandes
    Frederico Fernandes avatar
    20 posts
    Member since:
    Oct 2009

    Posted 08 Aug 2011 Link to this post

    Hi,

    I have several columns, placed on a group, by clicking at the group it selects it, how can i "Console.Writeline" this selected group?
    And how can i unselect it? it doesn't unselect when clicking other groups.

    Thanks,
    Sílvio F.
  8. Martin Vasilev
    Admin
    Martin Vasilev avatar
    1061 posts

    Posted 11 Aug 2011 Link to this post

    Hi Silvio,

    Thank you for contacting us.

    I am afraid I do not understand your scenario very well. Could you please elaborate on the exact issue you experience? Code snippets, detailed scenario description, screenshots or anything else you consider convenient will be of great help.

    I look forward to your reply.

    Best wishes,
    Martin Vasilev
    the Telerik team

    Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get now >>

  9. David
    David avatar
    2 posts
    Member since:
    Oct 2007

    Posted 03 Dec 2015 in reply to Martin Vasilev Link to this post

    Hi Martin,

     I know this is a very old post but I came across it while trying to figure out how to get the index of a GridViewRow. Am I missing something, because the RadGridView that I am working with in WPF doesn't have a Rows property or a CurrentRow property.

  10. Dimitar
    Admin
    Dimitar avatar
    1414 posts

    Posted 03 Dec 2015 Link to this post

    Hello David,

    Please note that this is the WinForms forum and the WinForms grid has different properties. This is why I would ask you to post your question in the appropriate forum section: Forum threads about GridView UI for WPF

    Thank you for your understanding.

    Regards,
    Dimitar
    Telerik
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
  11. David
    David avatar
    2 posts
    Member since:
    Oct 2007

    Posted 03 Dec 2015 in reply to Dimitar Link to this post

    Ok Dimitar. No problem. Google brought me here and I didn't know to look at the top of the page for the forum type. I will next time.
  12. fariba
    fariba avatar
    21 posts
    Member since:
    May 2014

    Posted 20 Apr Link to this post

    Hi

    how can I get The selected row index in hierarchical mode?

    thanks

    fariba

  13. Dimitar
    Admin
    Dimitar avatar
    1414 posts

    Posted 20 Apr Link to this post

    Hi Fariba,

    Thank you for writing.

    You can get the child rows index from the template:
    if (radGridView1.CurrentRow.HierarchyLevel == 1)
    {
         var index = radGridView1.Templates[0].Rows.IndexOf(radGridView1.CurrentRow);
    }

    I hope this will be useful. 

    Regards,
    Dimitar
    Telerik
    Do you need help with upgrading your AJAX, WPF or WinForms project? Check the Telerik API Analyzer and share your thoughts.
Back to Top
UI for WinForms is Visual Studio 2017 Ready