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

Scroll to row without selection

3 Answers 233 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Ken
Top achievements
Rank 1
Ken asked on 03 Feb 2012, 06:09 PM
In my case I want to scroll to the top row in certain circumstances.  The code that works isn't elegant as it will fire events that I really don't want.  To get around that I use a flag that I set before updating the grid, then reset after.  Here's the code:

            _fillingSearchGrid = true;
            SearchResultsGrid.DataSource = results;
            if (SearchResultsGrid.Rows.Count > 0)
            {
                SearchResultsGrid.CurrentRow = SearchResultsGrid.ChildRows[0];
                SearchResultsGrid.CurrentRow = null;
            }
            _fillingSearchGrid = false;

Is there a better way to do this?

3 Answers, 1 is accepted

Sort by
0
Ivan Petrov
Telerik team
answered on 08 Feb 2012, 04:20 PM
Hello Ken,

Thank you for writing.

If you will always be scrolling to the first row, you can simply move the scroll bar. Here is the code to scroll to the first row:
this.radGridView1.TableElement.VScrollBar.Value = 0;

You can also scroll to a specific row and/or column without changing the current selection by using the RadGridView.TableElement ScrollTo, ScrollToRow and ScrollToColumn methods.

I hope this will be useful for you. Should you have further questions, I would be glad to help.

All the best,
Ivan Petrov
the Telerik team
Sharpen your .NET Ninja skills! Attend Q1 webinar week and get a chance to win a license! Book your seat now >>
0
Ken
Top achievements
Rank 1
answered on 13 Feb 2012, 06:39 PM
Thanks, that works.  Now...is there any way to set a datasource without the first row in the grid being automatically selected?
0
Ivan Petrov
Telerik team
answered on 16 Feb 2012, 03:52 PM
Hi Ken,

Thank you for your reply.

You can use the CurrentRowChanging event to cancel the selection when you are binding the RadGridView.

Here is a code example of the above:
bool cancelSelection = false;
 
this.radGridView1.CurrentRowChanging += new CurrentRowChangingEventHandler(radGridView1_CurrentRowChanging);
this.cancelSelection = true;
this.radGridView1.DataSource = someSource;
this.cancelSelection = false;
 
private void radGridView1_CurrentRowChanging(object sender, CurrentRowChangingEventArgs e)
{
  e.Cancel = this.cancelSelection;
}

I hope this will help. If you need further assistance feel free to write back.

All the best,
Ivan Petrov
the Telerik team
Sharpen your .NET Ninja skills! Attend Q1 webinar week and get a chance to win a license! Book your seat now >>
Tags
GridView
Asked by
Ken
Top achievements
Rank 1
Answers by
Ivan Petrov
Telerik team
Ken
Top achievements
Rank 1
Share this question
or