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

[Solved] How to navigate and select rows in a radgridview using only keyboard.

5 Answers 319 Views
GridView
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
Ole
Top achievements
Rank 1
Ole asked on 08 Feb 2011, 07:06 PM
Hi,

I am trying to be able to navigate a gridview  and select multiple rows. 

<telerik:RadGridView x:Name="TraningEventEmployee"  AutoGenerateColumns="False"  SelectionMode="Multiple"  TabNavigation="Cycle">
                <telerik:RadGridView.Columns>
                    <telerik:GridViewDataColumn DataMemberBinding="{Binding Path=Name}" Header="Name" SortingState="Descending"/>
                    <telerik:GridViewDataColumn DataMemberBinding="{Binding Path=PhoneNumber}" Header="Phone"/>
                    <telerik:GridViewDataColumn DataMemberBinding="{Binding Path=SocialSecurityNumber}" Header="SSN"/>
                    <telerik:GridViewDataColumn DataMemberBinding="{Binding Path=Position1.Position1}" Header="Position"/>
                    <telerik:GridViewDataColumn DataMemberBinding="{Binding Path=Tasks.Task}" Header="Task"/>
                    <telerik:GridViewDataColumn DataMemberBinding="{Binding Path=WorkAreas.WorkArea}" Header="Work area"/>
  
                </telerik:RadGridView.Columns>
                  
  
            </telerik:RadGridView>

and

public EmployeesPopUpList(HSETrainingContext ctx)
        {
            InitializeComponent();
            GlbCtx = ctx;
            this.LayoutRoot.KeyUp += new KeyEventHandler(LayoutRoot_KeyUp);
            TraningEventEmployee.ItemsSource = GlbCtx.Employees;
}
and

void LayoutRoot_KeyUp(object sender, KeyEventArgs e)
       {
                       if (e.Key==Key.Enter)
           {
               this.DialogResult = true;
               this.Close();
           }
           if (e.Key == Key.Space)
           {
               TraningEventEmployee.SelectedItems.Add(TraningEventEmployee.CurrentItem);
           }
       }

However it seems like the currentitem always stays the same the first in the row in the gridview. How do I move the currentItem / get a hold of it ?, I am using up/down arrows to navigate in the grid.


Best regards

Ole Ronne

5 Answers, 1 is accepted

Sort by
0
Maya
Telerik team
answered on 09 Feb 2011, 07:46 AM
Hello Ole,

May you try to set the IsSynchronizedWithCurrentItem property of the grid to "True" ? 
 

Kind regards,
Maya
the Telerik team
Let us know about your Windows Phone 7 application built with RadControls and we will help you promote it. Learn more>>
0
Ole
Top achievements
Rank 1
answered on 09 Feb 2011, 11:08 AM
Hi,

Tried that and it did not change anything. Still current item always stays the same the first item you select(using normal mouseclick).

In mho this is very strange (bug)  since current item sholud reflect the selected cell  .

since the current cell shows correctly I made this workaround.

if (e.Key == Key.Space)
            {
                //TraningEventEmployee.SelectedItems.Add(TraningEventEmployee.CurrentItem);
                Employee curEmployee =    (Employee)  ((GridViewCellBase)(((GridViewDataControl)(TraningEventEmployee)).CurrentCell)).ParentRow.Item;
  
                TraningEventEmployee.SelectedItems.Add(curEmployee);
            }

Works but current item does not.

Best regards

Ole





0
Ole
Top achievements
Rank 1
answered on 09 Feb 2011, 01:28 PM
Hi,

Also why does pressing the enter key clears selected items in the gridview ?. Is this an exspected behavior ?.

best regards

Ole
0
Accepted
Maya
Telerik team
answered on 11 Feb 2011, 03:22 PM
Hi Ole,

The fact that pressing Enter key clears the selection is the expected behavior. Pressing the Tab key will have similar result. The behavior of both those keys is to select nothing but the current item only. You may take a look at this blog post  for a reference on how to modify this behavior. 
As far as changing the CurrentItem is concerned, this is also an expected result since you are setting the SelectionMode to "Multiple". In this case the selected and current item(s) remain the first one in the collection. You may try to set that property to "Extended" instead. For further reference please take a look at our online documentation
Additionally, following the settings you are using, you indeed may use the current cell. In this case however, the current item may not coincide with the current cell. But still the latter will be changed on navigating with the keys. So, this may be a good approach to take. 
 

Kind regards,
Maya
the Telerik team
Let us know about your Windows Phone 7 application built with RadControls and we will help you promote it. Learn more>>
0
Ole
Top achievements
Rank 1
answered on 11 Feb 2011, 05:17 PM
Ok,

Got this finally to work, used the blog link Thanks..

Have a nice week end.

Best

Ole.
Tags
GridView
Asked by
Ole
Top achievements
Rank 1
Answers by
Maya
Telerik team
Ole
Top achievements
Rank 1
Share this question
or