13 Answers, 1 is accepted
0
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:
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
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
0
sculver
Top achievements
Rank 1
answered on 27 Aug 2008, 04:57 PM
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?
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?
0
Hello sculver,
Thank you for writing.
You have to cast the current row to GridViewDataRowInfo. Please, review the code-block below as a reference:
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.
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.
0
Fernando
Top achievements
Rank 1
answered on 10 Sep 2010, 05:45 PM
Excelent!! Thank you!
0
Frederico Fernandes
Top achievements
Rank 1
answered on 08 Aug 2011, 07:44 PM
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.
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.
0
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
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 >>
0
David
Top achievements
Rank 1
answered on 03 Dec 2015, 11:48 AM
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.
0
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
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
0
David
Top achievements
Rank 1
answered on 03 Dec 2015, 12:26 PM
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.
0
Fariba
Top achievements
Rank 1
answered on 20 Apr 2016, 07:28 AM
Hi
how can I get The selected row index in hierarchical mode?
thanks
fariba
0
Hi Fariba,
Thank you for writing.
You can get the child rows index from the template:
I hope this will be useful.
Regards,
Dimitar
Telerik
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.
0
Stephen
Top achievements
Rank 1
answered on 29 Oct 2019, 10:40 PM
I have a similar problem where I want to get and set the index. Here it explains how to get the index but after a screen refresh of data how do I set the index?
0
Hi Stephen,
The following article shows how you can set the current row/column: Accessing and Setting the CurrentCell.
I hope this helps. Should you have any other questions do not hesitate to ask.
Regards,
Dimitar
Progress Telerik
Get quickly onboarded and successful with your Telerik and/or Kendo UI products with the Virtual Classroom free technical training, available to all active customers. Learn More.