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

Go no next row when the grid is sorted by a column

5 Answers 366 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Jill-Connie Lorentsen
Top achievements
Rank 1
Jill-Connie Lorentsen asked on 11 Sep 2009, 12:13 PM

I have a RadGridView, and a button "Next", which makes the selected row change to the one below when the user clicks on it:

int selectedIndex = this.radgrid.SelectedRows[0].GridViewInfo.CurrentIndex;
//Go to next index
selectedIndex++;

this.radgrid.CurrentRow = radgrid.Rows[selectedIndex];

The problem occurs when the grid is sorted by one column, say a Date column. If one date is expanded and a row is clicked, the CurrentIndex is the index of the row within the selected date. But when I try to set the CurrentRow, it is set to the "overall" index, as if the grid was not sorted.

Any ideas on how to solve this?

Regards, Jill-Connie Lorentsen

5 Answers, 1 is accepted

Sort by
0
Jack
Telerik team
answered on 11 Sep 2009, 02:03 PM
Hi Jill-Connie Lorentsen,

If you want to just move to the next row, you don't have to use CurrentIndex property. It returns a value relative to the CurrentGroup which is used internally. A better option is to use GridNavigator.SelectNextRow method. Here is sample code:

this.radGridView1.GridNavigator.SelectNextRow(1, falsefalse); 

It will move the current position in RadGridView to the next row regardless whether the grid is sorted or not.

I hope this helps. If not, please describe in detail what exactly you want to achieve and I will try to find a proper solution. A sample project will be very helpful as well.

I am looking forward to your reply.

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
Jill-Connie Lorentsen
Top achievements
Rank 1
answered on 14 Sep 2009, 09:18 AM

Thank you, - that helped! A bit...

When I reach the last row within the selected date and press Next, I would like the selected row to be the first within the next date.

How can I accomplish this?

Regards, Jill-Connie Lorentsen

0
Jack
Telerik team
answered on 14 Sep 2009, 02:59 PM
Hi Jill-Connie Lorentsen,

I am not sure that I understand what you want to achieve. Please, send me your application. This will help me to understand the issue and find a proper solution. I am looking forward to your reply.

Best wishes,
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
Jill-Connie Lorentsen
Top achievements
Rank 1
answered on 15 Sep 2009, 07:55 AM

I'm afraid I can't send you my application. I could make a sample application, but I think I'll try to explain my problem more thoroughly first.

I have a gridview with many rows. When the user clicks one of the rows, the information in the row is being pulled out an displayed. I also have a button Next, so that the user can click it instead of clicking in the grid, moving to the next row in the grid. If the grid is not grouped everything works fine.

Then I group the grid by one column, say Date. I do this by dragging the Date column to the top of the grid, and the grid is collapsed so that only the dates are shown. 

Then I expand one of the dates, so that the rows for this date is shown. I then have some collapsed dates, and one expanded.

The user clicks one of the rows in the expanded date, the information is displayed, the user clicks Next and the information in the next row is displayed. UNTIL the end of the expanded date is reached. The last row is of course displayed fine, but when the user then clicks Next it seems like the next row is the collapsed row showing only the date.

I would like the behavior to be the same as if the grid was not grouped.  

If you still don't understand what I mean, I'll make a sample application.

Thank you for your help!

Regards, Jill-Connie Lorentsen

0
Jack
Telerik team
answered on 15 Sep 2009, 10:04 AM
Hello Jill-Connie Lorentsen,

Thank you for the detailed description. Now I understand the issue. You can check whether CurrentRow is GridViewGroupRowInfo in this case. Look at the code snippet below:

while (this.radGridView1.GridNavigator.SelectNextRow(1, falsefalse) && 
    this.radGridView1.CurrentRow is GridViewGroupRowInfo) 
    if (this.radGridView1.CurrentRow is GridViewGroupRowInfo) 
    { 
        ((GridViewGroupRowInfo)this.radGridView1.CurrentRow).IsExpanded = true
    } 

Additionally you can expand all groups by setting AutoExpandGroups property to true:

this.radGridView1.MasterGridViewTemplate.AutoExpandGroups = true

Should you have any further questions, feel free to write me back.

Greetings,
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.
Tags
GridView
Asked by
Jill-Connie Lorentsen
Top achievements
Rank 1
Answers by
Jack
Telerik team
Jill-Connie Lorentsen
Top achievements
Rank 1
Share this question
or