how do I programmatically set the selected row?

17 posts, 1 answers
  1. Scott
    Scott avatar
    43 posts
    Member since:
    Nov 2007

    Posted 22 Oct 2008 Link to this post

    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)
  2. Atanas
    Admin
    Atanas avatar
    54 posts

    Posted 23 Oct 2008 Link to this post

    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.
  3. UI for WPF is Visual Studio 2017 Ready
  4. Scott
    Scott avatar
    43 posts
    Member since:
    Nov 2007

    Posted 23 Oct 2008 Link to this post

    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.

  5. Answer
    Atanas
    Admin
    Atanas avatar
    54 posts

    Posted 23 Oct 2008 Link to this post

    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.
  6. Erez
    Erez avatar
    55 posts
    Member since:
    Jun 2009

    Posted 29 Jun 2009 Link to this post

    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

     

     

  7. Milan
    Admin
    Milan avatar
    1989 posts

    Posted 29 Jun 2009 Link to this post

    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.
  8. Erez
    Erez avatar
    55 posts
    Member since:
    Jun 2009

    Posted 30 Jun 2009 Link to this post

    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

  9. Milan
    Admin
    Milan avatar
    1989 posts

    Posted 03 Jul 2009 Link to this post

    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.
  10. Erez
    Erez avatar
    55 posts
    Member since:
    Jun 2009

    Posted 16 Jul 2009 Link to this post

    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

  11. Missing user
    Missing user avatar

    Posted 16 Jul 2009 Link to this post

    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.
  12. Erez
    Erez avatar
    55 posts
    Member since:
    Jun 2009

    Posted 23 Jul 2009 Link to this post

    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
  13. Milan
    Admin
    Milan avatar
    1989 posts

    Posted 24 Jul 2009 Link to this post

    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.
  14. Erez
    Erez avatar
    55 posts
    Member since:
    Jun 2009

    Posted 26 Jul 2009 Link to this post

    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

  15. Erez
    Erez avatar
    55 posts
    Member since:
    Jun 2009

    Posted 26 Jul 2009 Link to this post

    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
  16. Milan
    Admin
    Milan avatar
    1989 posts

    Posted 30 Jul 2009 Link to this post

    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.
  17. Mike Picco
    Mike Picco avatar
    2 posts
    Member since:
    Dec 2009

    Posted 01 Nov 2011 Link to this post

    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
     
  18. Dilum
    Dilum avatar
    1 posts
    Member since:
    Aug 2012

    Posted 01 Nov 2012 Link to this post

    Well, following is the way I've coded to make the first row of the grid selected:

    if (grdBills.HasItems)
                    grdBills.SelectedItem = grdBills.Items[0];
Back to Top
UI for WPF is Visual Studio 2017 Ready