Hello.
My problem is that i cannot move selected item when click up/down keyboard button like:
private void Window_PreviewKeyDown(object sender, KeyEventArgs e)
{
if (e.Key == Key.Down)
...
}
Is there any way to move selection when I press up/down button?
Thanks in advance,
Regards
My problem is that i cannot move selected item when click up/down keyboard button like:
private void Window_PreviewKeyDown(object sender, KeyEventArgs e)
{
if (e.Key == Key.Down)
...
}
Is there any way to move selection when I press up/down button?
Thanks in advance,
Regards
6 Answers, 1 is accepted
0
Hi,
Let me know how this works for you.
Regards,
Didie
Telerik
You can select the next(previous) item with a similar code:
if
(e.Key == Key.Down)
{
this
.clubsGrid.PendingCommands.Clear();
this
.clubsGrid.PendingCommands.Add(RadGridViewCommands.MoveDown);
this
.clubsGrid.PendingCommands.Add(RadGridViewCommands.SelectCurrentItem);
this
.clubsGrid.ExecutePendingCommand();
e.Handled =
true
;
}
Let me know how this works for you.
Regards,
Didie
Telerik
TRY TELERIK'S NEWEST PRODUCT - EQATEC APPLICATION ANALYTICS for WPF.
Learn what features your users use (or don't use) in your application. Know your audience. Target it better. Develop wisely.
Sign up for Free application insights >>
Learn what features your users use (or don't use) in your application. Know your audience. Target it better. Develop wisely.
Sign up for Free application insights >>
0

Paweł
Top achievements
Rank 1
answered on 30 Jul 2013, 08:32 AM
Hi and thanks for answer.
Unfortunately that doesn't work for me. It does focus first row in grid, but its not really like selection :) I mean normally selected row have blue background, but with Your example it's making only "frame" around row, and pressing Down again doesnt really select next item in dg.
That code work's for me:
Key.Down:
int ind;
if (statusDG.SelectedItem == null)
ind = -1;
else
ind = statusDG.Items.IndexOf(statusDG.SelectedItem);
if (ind == statusDG.Items.Count - 1)
return;
statusDG.SelectedItem = statusDG.Items[ind + 1];
statusDG.Focus();
Key.Up:
int ind = statusDG.Items.IndexOf(statusDG.SelectedItem);
if (ind == 0)
return;
statusDG.SelectedItem = statusDG.Items[ind - 1];
LoseFocusOnTB.LoseFocus(tb);
statusDG.Focus();
Unfortunately that doesn't work for me. It does focus first row in grid, but its not really like selection :) I mean normally selected row have blue background, but with Your example it's making only "frame" around row, and pressing Down again doesnt really select next item in dg.
That code work's for me:
Key.Down:
int ind;
if (statusDG.SelectedItem == null)
ind = -1;
else
ind = statusDG.Items.IndexOf(statusDG.SelectedItem);
if (ind == statusDG.Items.Count - 1)
return;
statusDG.SelectedItem = statusDG.Items[ind + 1];
statusDG.Focus();
Key.Up:
int ind = statusDG.Items.IndexOf(statusDG.SelectedItem);
if (ind == 0)
return;
statusDG.SelectedItem = statusDG.Items[ind - 1];
LoseFocusOnTB.LoseFocus(tb);
statusDG.Focus();
0
Hi,
Didie
Telerik
The code I suggested works perfectly on my side and I am not sure what would be the difference with your implementation. If you send us a support ticket with a demo project, then we can investigate the case further.
Thank you for sharing your solution with the community.
Didie
Telerik
TRY TELERIK'S NEWEST PRODUCT - EQATEC APPLICATION ANALYTICS for WPF.
Learn what features your users use (or don't use) in your application. Know your audience. Target it better. Develop wisely.
Sign up for Free application insights >>
Learn what features your users use (or don't use) in your application. Know your audience. Target it better. Develop wisely.
Sign up for Free application insights >>
0

Yannick Turbang
Top achievements
Rank 1
answered on 25 Oct 2019, 09:18 AM
Hi,
In fact it's very easy to do that here is my solution.
First you need to implement the mouse click event.
After that you just need to call the mouse click event from the PreviewKeyUp Event.
Also add the SelectionMode="Single" to the grid
private
void
DG_Logs_PreviewMouseLeftButtonUp(
object
sender, MouseButtonEventArgs e)
{
//Implement the mouve click event on the row here.
string
message = ((LoggerViewer.Model.DataItems.di_GrilleLogs)
((Telerik.Windows.Controls.DataControl)sender).SelectedItem).Log_Message;
}
private
void
DG_Logs_PreviewKeyUp(
object
sender, KeyEventArgs e)
{
DG_Logs_PreviewMouseLeftButtonUp(sender,
null
);
}
0

Yannick Turbang
Top achievements
Rank 1
answered on 25 Oct 2019, 09:35 AM
Here is the same solution with MVVM Light
<
telerik:RadGridView
Name
=
"DataGrid"
ItemsSource
=
"{Binding DGPxxx}"
SelectionMode
=
"Single"
SelectedItem
=
"{Binding DGPxxx_selecteditem, Mode=TwoWay}"
>
<
i:Interaction.Triggers
>
<
i:EventTrigger
EventName
=
"PreviewMouseUp"
>
<
MVVVMLightCommand:EventToCommand
Command
=
"{Binding DGPxxxClick, Mode=OneWay}"
/>
</
i:EventTrigger
>
<
i:EventTrigger
EventName
=
"PreviewKeyUp"
>
<
MVVVMLightCommand:EventToCommand
Command
=
"{Binding DGPxxxClick, Mode=OneWay}"
/>
</
i:EventTrigger
>
</
i:Interaction.Triggers
>
0
Hi Yannick,
Thank you for sharing your solution with our community.
Regards,
Dilyan Traykov
Progress Telerik
Get quickly onboarded and successful with your Telerik and/or Kendo UI products with the Virtual Classroom free technical training, available to all active customers. Learn More.