Contact Sales: +1-888-365-2779
Community & Support
Skip Navigation LinksHome / Community & Support / Developer Productivity Tools Forums / WPF > GridView > how do I programmatically set the selected row?

Answered how do I programmatically set the selected row?

Feed from this thread
  • Posted on Oct 22, 2008 (permalink)

    in my listboxes I use listbox.SelectedIndex++, I want to select the next row in my WPF GridView (I have paging arrows at the top that will navigate through the grid)

    Reply

  • Atanas Atanas admin's avatar

    Posted on Oct 23, 2008 (permalink)

    Hi Scott,

    Could you please give some more details about your approach or send a sample project to test locally and try to find a solution for you? Step-by-step details on how to reproduce the problem will also be greatly appreciated.

    Best wishes,
    Atanas
    the Telerik team

    Check out Telerik Trainer, the state of the art learning tool for Telerik products.

    Reply

  • Q1 Webinar Week
  • Posted on Oct 23, 2008 (permalink)

    I have a grid with 10 rows in it.  When I click a button on my page, I want the next row to be selected.  I want to control the selected row in my grid programmatically.    That's it.

    Reply

  • Answer Atanas Atanas admin's avatar

    Posted on Oct 23, 2008 (permalink)

    Hi Scott,

    Our Records have a boolean type property IsSelected and you have to play with it, to select a single row programmatically.

    I am attaching a sample project compliant with your scenario. I hope this solves your issue. If you have any other questions, please do not hesitate to write us.

    Greetings,
    Atanas
    the Telerik team

    Check out Telerik Trainer, the state of the art learning tool for Telerik products.

    Reply

  • Erez avatar

    Posted on Jun 29, 2009 (permalink)

    Hello,

    Greate example, however how about updating the visual scroll bar focus ?

    Right now, if the 'next row' if off screen, the user has to manualy change the scroll bar to view it.

     

    Thanks,

     

    Erez

     

     

    Reply

  • Milan Milan admin's avatar

    Posted on Jun 29, 2009 (permalink)

    Hello Erez,

    To bring an item into view you can use the method called BringDataItemIntoView. If you would like to scroll to the SelectedRecord you can do the following:

    DataRecord record = (DataRecord)this.RadGridView1.SelectedRecord;  
    this.RadGridView1.BringDataItemIntoView(record.Data); 

    Hope this helps.

    Sincerely yours,
    Milan
    the Telerik team

    Instantly find answers to your questions on the new Telerik Support Portal.
    Check out the tips for optimizing your support resource searches.

    Reply

  • Erez avatar

    Posted on Jun 30, 2009 (permalink)

    Hi Milan,

    It seems that there is a problem with "BringDataItemIntoView".

    If I have, for example, just three rows in my grid, and I activate the "BringDataItemIntoView" method on

    the second row, the first row disappears. I have to use the mouse wheel to make it appear.

    Seems like a bug someone reported way back before Q1.

    Thanks,

    Erez

    Reply

  • Milan Milan admin's avatar

    Posted on Jul 3, 2009 (permalink)

    Hello Erez,

    It seems that you are using very old version of our WPF controls (Q2 2008). If the ticket information is correct you can try to update to a newer version. Our latest version introduces many bug fixes, including the one with BrindDataItemIntoView, and many new features.

    Kind regards,
    Milan
    the Telerik team

    Instantly find answers to your questions on the new Telerik Support Portal.
    Check out the tips for optimizing your support resource searches.

    Reply

  • Erez avatar

    Posted on Jul 16, 2009 (permalink)

    Hello,

    If I want to update, do I need to uninstall the previous (2009q1) or just run the new MSI ?

    Regarding existing projects, am I to assume correctly that I will manually have to change their references the the 2009q2 dlls ?

    Thanks,

     

    Erez

    Reply

  • Anastasia Anastasia admin's avatar

    Posted on Jul 16, 2009 (permalink)

    Hi Erez,

     You do not need to uninstall the previous version of our controls to run the new MSI, uninstalling is only required for the service pack installers.

     Your assumption is correct, to have your existing projects using the latest 2009Q2 binaries you need to manually change their references.

    Best wishes,
    Anastasia
    the Telerik team

    Instantly find answers to your questions on the new Telerik Support Portal.
    Check out the tips for optimizing your support resource searches.

    Reply

  • Erez avatar

    Posted on Jul 23, 2009 (permalink)

    Hello,

    Regarding the Jul 16 and BringDataItemIntoView'.

    I am sorry to say but it seems the 'BringDataItemIntoView' still exists in 2009Q2.

    If I have, for example, three rows in the grid (dataView connected) and visible space to put some more and I activate the method on the last row (DataRowView item) a disabled vertical scroll bar appears (although it is not required) and the first row "disappears". I have to scroll with the Up Down arrows to see it.



    Thanks,

    Erez

    Reply

  • Milan Milan admin's avatar

    Posted on Jul 24, 2009 (permalink)

    Hello Erez,

    I was not able to reproduce the issue. I am sending you a sample project that brings into view the last record but the problem does not appear. Could you try reproducing it?

    All the best,
    Milan
    the Telerik team

    Instantly find answers to your questions on the new Telerik Support Portal.
    Check out the tips for optimizing your support resource searches.

    Reply

  • Erez avatar

    Posted on Jul 26, 2009 (permalink)

    Hi Milan

    Please use this as the data source instead of Message:

            public Window1()
            {
                InitializeComponent();

                DataTable dt = new DataTable();
                DataView dv;

                dt.Columns.Add("Display", typeof(string));
                dt.Columns.Add("Number", typeof(int));

                dt.Rows.Add("show", 1);
                dt.Rows.Add("show", 2);
                dt.Rows.Add("hide", 3);
                dt.Rows.Add("show", 4);
                dt.Rows.Add("show", 5);

                dv = new DataView(dt);

                dv.RowFilter = "Display = 'show'";

                RadGridView1.ItemsSource = dv;
            }

    Change the event as follows:

            private void Button_Click(object sender, RoutedEventArgs e)
            {
                int c;
                ((DataView)this.RadGridView1.ItemsSource).Table.Rows.Add("show", 5);

                c = ((DataView)this.RadGridView1.ItemsSource).Table.Rows.Count;
                if (c > 1)
                {
                    var thirdItem = ((IList)this.RadGridView1.ItemsSource)[c-2];
                    this.RadGridView1.BringDataItemIntoView(thirdItem);
                }
            }

    Run it and give a couple of clicks on the button.

    Thanks,

    Erez

    Reply

  • Erez avatar

    Posted on Jul 26, 2009 (permalink)

    One more important note-

    The problem seems to be related to the line:
    ' dv.RowFilter = "Display = 'show'";  '


    If you remark it out, the phenomenon does not occur.

    Thanks,

    Erez

    Reply

  • Milan Milan admin's avatar

    Posted on Jul 30, 2009 (permalink)

    Hello Erez,

    Thre is indeed a problem but I believe it is actually related to adding new items just before the call to BringDataItemIntoView. We have logged the issue and we will try to fix it as soon as possible. 

    Fortunately there might be a workaround that can work for you - you can try running BrindDataItemIntoView through the Dispatcher.

    private void Button_Click(object sender, RoutedEventArgs e)  
    {  
        int c;  
        ((DataView)this.RadGridView1.ItemsSource).Table.Rows.Add("show", 5);  
     
        c = ((DataView)this.RadGridView1.ItemsSource).Table.Rows.Count;  
        if (c > 1)  
        {  
            this.Dispatcher.BeginInvoke((Action)delegate  
            {  
                var thirdItem = ((IList)this.RadGridView1.ItemsSource)[c - 2];  
                this.RadGridView1.BringDataItemIntoView(thirdItem);  
     
            }, DispatcherPriority.SystemIdle, null);  
        }  

    Hope this helps.

    Regards,
    Milan
    the Telerik team

    Instantly find answers to your questions on the new Telerik Support Portal.
    Check out the tips for optimizing your support resource searches.

    Reply

  • Mike Picco avatar

    Posted on Nov 1, 2011 (permalink)

    I know that this forum entry is dated and I have made the necessary modifications to my code to account for the changes but I am still having an issue.  I want to programatically select a record in a gridview.  I am using the following line of code to do that and the program is correctly selecting the record in the gridview.  The problem is that it is also "indicating" the selection of another record (the first one in the gridveiw).  When I step through the program I see the the other row is not actually selected but the visual highlighting of the row is still there.  Any ideas?

    Ex:

    this.GV_RightSide.Rows[0].IsSelected = false;

    this.GV_RightSide.Rows[2].IsSelected = true;

     
    Expectation:

    Row[0] should not be selected and shold not be highlighted.  Row[2] should be selected and should be highlighted.

    Actual Result:

    Row[0] is not selected but IS still highlighted.  Row[2] is selected and is also highlighted.

    One final note, I do have multirow select enabled (which is what I want).

    Thanks,

    Mike
     

    Reply

  • Q1 Webinar Week

Back to Top

Skip Navigation LinksHome / Community & Support / Developer Productivity Tools Forums / WPF > GridView > how do I programmatically set the selected row?
Related resources for "how do I programmatically set the selected row?"

WPF Grid Features  |  Documentation  |  Demos  |  Telerik TV  |  Self-Paced Trainer  ]