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

how do I programmatically set the selected row?

16 Answers 1119 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Scott
Top achievements
Rank 1
Scott asked on 22 Oct 2008, 05:39 PM
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)

16 Answers, 1 is accepted

Sort by
0
Atanas
Telerik team
answered on 23 Oct 2008, 06:47 AM
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.
0
Scott
Top achievements
Rank 1
answered on 23 Oct 2008, 12:40 PM
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.

0
Accepted
Atanas
Telerik team
answered on 23 Oct 2008, 02:22 PM
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.
0
Erez
Top achievements
Rank 1
answered on 29 Jun 2009, 06:26 AM

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

 

 

0
Milan
Telerik team
answered on 29 Jun 2009, 09:35 PM
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.
0
Erez
Top achievements
Rank 1
answered on 30 Jun 2009, 04:11 PM

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

0
Milan
Telerik team
answered on 03 Jul 2009, 10:06 AM
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.
0
Erez
Top achievements
Rank 1
answered on 16 Jul 2009, 05:41 AM

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

0
Missing User
answered on 16 Jul 2009, 07:06 AM
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.
0
Erez
Top achievements
Rank 1
answered on 23 Jul 2009, 08:46 AM
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
0
Milan
Telerik team
answered on 24 Jul 2009, 05:38 AM
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.
0
Erez
Top achievements
Rank 1
answered on 26 Jul 2009, 07:18 AM

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

0
Erez
Top achievements
Rank 1
answered on 26 Jul 2009, 07:22 AM
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
0
Milan
Telerik team
answered on 30 Jul 2009, 06:35 AM
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.
0
Mike Picco
Top achievements
Rank 1
answered on 01 Nov 2011, 01:14 PM
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
 
0
Dilum
Top achievements
Rank 1
answered on 01 Nov 2012, 11:46 AM
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];
Tags
GridView
Asked by
Scott
Top achievements
Rank 1
Answers by
Atanas
Telerik team
Scott
Top achievements
Rank 1
Erez
Top achievements
Rank 1
Milan
Telerik team
Missing User
Mike Picco
Top achievements
Rank 1
Dilum
Top achievements
Rank 1
Share this question
or