Skip Navigation LinksHome / Community & Support / Developer Productivity Tools Forums / WinForms > GridView > Scroll to row without selection

Not answered Scroll to row without selection

Feed from this thread
  • Ken avatar

    Posted on Feb 3, 2012 (permalink)

    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?

    Reply

  • Ivan Petrov Ivan Petrov admin's avatar

    Posted on Feb 8, 2012 (permalink)

    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 >>

    Reply

  • Ken avatar

    Posted on Feb 13, 2012 (permalink)

    Thanks, that works.  Now...is there any way to set a datasource without the first row in the grid being automatically selected?

    Reply

  • Ivan Petrov Ivan Petrov admin's avatar

    Posted on Feb 16, 2012 (permalink)

    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 >>

    Reply

Back to Top

Skip Navigation LinksHome / Community & Support / Developer Productivity Tools Forums / WinForms > GridView > Scroll to row without selection
Related resources for "Scroll to row without selection"

[ Features | Demos | Documentation | Knowledge Base | Telerik TV | Code Library | Step-by-step Tutorial | Blogs | Self-Paced Trainer ]