This is a migrated thread and some comments may be shown as answers.

Select first row when grouping

4 Answers 101 Views
GridView
This is a migrated thread and some comments may be shown as answers.
jc mag
Top achievements
Rank 1
jc mag asked on 28 Sep 2009, 02:57 PM
I have a grid with grouped rows, I call ExpandAllGroups, then I'd like the first row of the first group to be selected. (currently the grid scrolls to display the first row of the datasource, I think).
How could I do that?

 

4 Answers, 1 is accepted

Sort by
0
Jack
Telerik team
answered on 29 Sep 2009, 09:55 AM
Hi jc mag,

You should use Groups collection of RadGridView. It contains the groups. Just set IsCurrent property of the HeaderRow of the desired group. Please look at the sample below:

if (this.radGridView1.Groups.Count > 0) 
    this.radGridView1.Groups[0].HeaderRow.IsCurrent = true

I hope it helps. If you have more questions, don't hesitate to contact us.

Regards,
Jack
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
0
Curtis
Top achievements
Rank 1
Veteran
answered on 20 Jul 2018, 10:22 PM

I'm pretty sure the previous posts are out-dated since there are a number of properties that no longer exist - I'm using the latest version of RadGridView for WinForms

 

I have a grid that's grouped by column "Type" and further is sorted by "Name"

If I select the 5th row down...then later I mygrid.Rows.Clear and then I reload the grid...the 5th row down is still selected so that's my first question:  How do I CLEAR the currentrow?    Here's what I have so far:

For Each myRow As GridViewRowInfo In MCGrid.Rows
    myRow.IsSelected = False
Next
MCGrid.ClearSelection()
MCGrid.CurrentRow = Nothing
MCGrid.Rows.Clear()

 

As you can see I'm throwing everything at the grid except the kitchen sink...the above code IS running prior to me reloading the grid...but when the grid reloads - there I am, right back at the same row as previously selected :(

 

My next question is why I'm in this thread:  How do you select the first row DISPLAYED (regardless of what group it may be in)?

Also - while I do have my grid grouped like this:

MCGrid.GroupDescriptors.Clear()
Dim descriptor As New GroupDescriptor()
descriptor.GroupNames.Add("MessageCodeType", ListSortDirection.Ascending)
MCGrid.GroupDescriptors.Add(descriptor)

 

If I check myGrid.Groups.Count it will = 0 - Shouldn't the groups collection get automatically filled when the grid loads or is there something more I need to do?

 

Any assistance/help/guidance would be very appreciated!

-Curtis

 

0
Dess | Tech Support Engineer, Principal
Telerik team
answered on 23 Jul 2018, 08:11 AM
Hello, Curtis,    

This is a very old post and the provided solution is relevant for the version of RadGridView back in 2009. Note that the RadGridView control has been refactored after that. We wanted to keep most of the public API unchanged but indeed some of the properties/methods no longer exist. 
Straight to your question:
- You can simply set the CurrentRow property to null after populating with data if you need to clear the selection.  
- After you group the grid, the RadGridView.ChildRows collection will contain all groups. Then, if you need to select the first row in the first group, you can simply select the RadGridView.ChildRows[0].ChildRows[0]. Additional information about the Rows and ChildRows collection is available in the following help article: https://docs.telerik.com/devtools/winforms/gridview/rows/rows-vs-childrows

I hope this information helps. If you have any additional questions, please let me know.  
 
Regards,
Dess
Progress Telerik
Try our brand new, jQuery-free Angular components built from ground-up which deliver the business app essential building blocks - a grid component, data visualization (charts) and form elements.
0
Curtis
Top achievements
Rank 1
Veteran
answered on 23 Jul 2018, 05:44 PM

Oh!  You folks made it easy as Pie didn't you!? :)

Thanks Dess.  That explains a ton and makes life a whole heck of a lot easier.

Have a great day.

Tags
GridView
Asked by
jc mag
Top achievements
Rank 1
Answers by
Jack
Telerik team
Curtis
Top achievements
Rank 1
Veteran
Dess | Tech Support Engineer, Principal
Telerik team
Share this question
or