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

Select next row and previos row

4 Answers 140 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Jomey
Top achievements
Rank 1
Jomey asked on 05 Sep 2008, 05:47 PM
I have a radgrid with a detailsview.  I added First, next, previous, last buttons on the top manually.   My grid has a GridButtonColumn (select).  When I click the select button i see the details.

When I click the "next" button i want the grid to select the next row and trigger the SelectedIndexChanged event - which triggers the details view.  When I click "previous" - it should select the previous row.

What's the easiest way to do this?  How do i set the rowindex of the grid?

4 Answers, 1 is accepted

Sort by
0
Shinu
Top achievements
Rank 2
answered on 08 Sep 2008, 06:03 AM
Hi Jomey,

Try the following code snippet to achieve the desired scenario.

CS:
protected void RadGrid2_ItemCommand(object source, GridCommandEventArgs e) 
    { 
        if (e.CommandName == "Select") 
        { 
            GridDataItem item = (GridDataItem)e.Item; 
            item.Expanded = true
        } 
        if (e.CommandName == "Next") 
        { 
            foreach (GridDataItem item in RadGrid2.MasterTableView.Items) 
            { 
                if (item.Selected) 
                { 
                    item.Selected = false
                    item.Expanded = false
                    int CurrentIndx = item.ItemIndex; 
                    int NextIndx = CurrentIndx + 1; 
                    RadGrid2.MasterTableView.Items[NextIndx].Selected = true
                    RadGrid2.MasterTableView.Items[NextIndx].Expanded = true
                    break; 
                } 
                 
            } 
        } 
        else if (e.CommandName == "Previous") 
        { 
            foreach (GridDataItem item in RadGrid2.MasterTableView.Items) 
            { 
                if (item.Selected) 
                { 
                    item.Selected = false
                    item.Expanded = false
                    int CurrentIndx = item.ItemIndex; 
                    int PrevIndx = CurrentIndx - 1; 
                    RadGrid2.MasterTableView.Items[PrevIndx].Selected = true
                    RadGrid2.MasterTableView.Items[PrevIndx].Expanded = true
                    break; 
                } 
 
            } 
        } 
         
 
    } 


Regards
Shinu.
0
Jomey
Top achievements
Rank 1
answered on 08 Sep 2008, 09:01 PM
thx,

my next question is - since i set a height to my grid - it has vertical scrollbars.  I click the next button until the grid's last item is highlighted - this works.  But the scrollbar doesn't scroll everytime i click the next button. 

I have to manually go to it and scroll to the bottom to see the highlighted item.

Is there a way so the scrollbar automatically scrolls along with clicking the next button?  To focus on the item that is selected.

I tried gvHRD.MasterTableView.Items[NextIndx].Focus();
0
Shinu
Top achievements
Rank 2
answered on 09 Sep 2008, 04:51 AM
Hi Jomey,

Here is a help article which explains how to scroll to the selected item in Grid. Go through it and see if it helps to some extent.
Scrolling to the selected item

Thanks
Shinu.

0
Jomey
Top achievements
Rank 1
answered on 09 Sep 2008, 05:14 PM
This won't work for me because I need it to scroll when I click the next button.

And var scrollArea = RadGrid1.GridDataDiv; is null.

Is there a way to use scrolltop when clicking the next button?
Tags
Grid
Asked by
Jomey
Top achievements
Rank 1
Answers by
Shinu
Top achievements
Rank 2
Jomey
Top achievements
Rank 1
Share this question
or