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

Select and FocusFirst Row

7 Answers 222 Views
GridView
This is a migrated thread and some comments may be shown as answers.
VS
Top achievements
Rank 1
VS asked on 11 Feb 2010, 06:10 AM
Hi,

Is there a way to select and focus first row in grid at design time. I am using MVVM pattern. Since i cant get access to the grid from ViewModel and also dont want to write any code in codebehind, is it possible to do this at design time in View.
When i give SelectedIndex="0", it selects the fist row, but the focus is not there.

Any help is much appreciated.

Thanks

Sujith

7 Answers, 1 is accepted

Sort by
0
Vlad
Telerik team
answered on 11 Feb 2010, 07:43 AM
Hello Sujith,

You can bind the grid SelectedItem to a property of your model:

SelectedItem="{Binding YourProperty, Mode=TwoWay}"

You can do the same with CurrentItem.

Sincerely yours,
Vlad
the Telerik team

Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
Follow the status of features or bugs in PITS and vote for them to affect their priority.
0
VS
Top achievements
Rank 1
answered on 12 Feb 2010, 01:23 AM
Hi,

I didnt get the property part..what property should i use for this?
i just need to focus the first row when the form is loaded, so that users can use arrow keys to move down or up the rows.

Regards

Sujith
0
VS
Top achievements
Rank 1
answered on 16 Feb 2010, 03:17 AM
When i do as below in the window

FocusManager.FocusedElement

 

="{Binding ElementName=myDataGrid}"
and put selectedindex="0" in the grid, the first row is selected and the grid is having focus and as a result, if i use down and up arrow keys, am able to move around the rows..
But my grid is in a usercontrol. The First row is selected and the grid is having focus but when using arrow keys, rows selections are not changed.

Any help is appreciated.

Regards

Sujith

 

0
Stefan Dobrev
Telerik team
answered on 17 Feb 2010, 09:18 AM
Hi Sujith,

It seems some other element is taking the focus out of the grid. Can you do the following: in your UserControl with the grid you can subscribe to the Loaded event. In the event handler you can use the following code:
this.Dispatcher.BeginInvoke((Action)() => this.MyGridView.Focus());

This should focus the grid view so that the keyboard navigation should work as expected.

Greetings,
Stefan Dobrev
the Telerik team

Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items.
0
VS
Top achievements
Rank 1
answered on 17 Feb 2010, 10:58 AM
Hi Stefan,

I can't use the Loaded event of the user control, since am using MVVM Pattern.

Any other solution? Am stuck with this problem.

REgards

Sujith
0
Stefan Dobrev
Telerik team
answered on 17 Feb 2010, 11:07 AM
Hi Sujith,

You can create an attached behavior that implements this behavior. This way you will not break the MVVM paradigm and isolated this code in the behavior.

Greetings,
Stefan Dobrev
the Telerik team

Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items.
0
VS
Top achievements
Rank 1
answered on 29 Mar 2010, 07:29 AM
Hi Stefan,
Do u have an example for this?

Tags
GridView
Asked by
VS
Top achievements
Rank 1
Answers by
Vlad
Telerik team
VS
Top achievements
Rank 1
Stefan Dobrev
Telerik team
Share this question
or