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

How to find if ctrl key is pressed during row selection?

5 Answers 53 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Joe
Top achievements
Rank 1
Joe asked on 02 Dec 2011, 10:32 PM
I just found that my selected rows is gone during paging even I pressed CTRL.
So I have to implement an Array to store my selections between paging, but here comes another problem, so if the user hold CTRL key, I will keep the previous selected items before paging, otherwise, I will not keep that into the array. but , how I can find if the CTRL key is pressed during the selection?

5 Answers, 1 is accepted

Sort by
0
Dimitrina
Telerik team
answered on 06 Dec 2011, 03:31 PM
Hello Joe,

When an item is selected, you could check if the Ctrl button was pressed like so:
bool controlModifier = ((Keyboard.Modifiers & ModifierKeys.Control) == ModifierKeys.Control);

I hope that this is what you need.

Kind regards,
Didie
the Telerik team
Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get it now >>
0
Joe
Top achievements
Rank 1
answered on 07 Dec 2011, 01:18 AM
This always return me false.
I capture this at selectionChanging event. 
0
Dimitrina
Telerik team
answered on 07 Dec 2011, 02:32 PM
Hello Joe,

I am capturing it inside the SelectionChanging event and it works as expected (returns True if I hold the Ctrl button). I am testing with the Q3 version of the RadControls. 

What is the result if you use the SelectionChanged event?

Kind regards,
Didie
the Telerik team

Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get it now >>

0
Joe
Top achievements
Rank 1
answered on 07 Dec 2011, 07:02 PM
Hi Didie,
Thinks get more complicated. But my scenario is simple: keep selected rows for RadGridView with paging using RadDataPager. I want to keep the selected rows after paging:
1. if the user press "ctrl" key, I will keep the selected rows from the previous page
2. otherwise, do not keep the previous selection.
3. after paging again the previous page, the selected item should show selected and I should be able to deselect them.
So, I met a couple of difficulties here by the limit of RadGridView and RadDataPager
1. how to iterate the rows of the gridview to set them into isSelected = true state, it looks like that I can not iterate all of the rows
2. once the paging is happening, it will have selectionchanging event to lost all of the previous selection since RadDataPager does not know anything about the previous page, this is strange design.

Can you have a small example (in code) to illustrate how to implement this scenario? I follow this example
http://www.dotneter.com/keep-selected-rows-when-paging-in-radgrid-telerik
but this is for a grid, and I can iterate through rows, but not gridview
0
Tyree
Top achievements
Rank 2
answered on 08 Dec 2011, 12:21 AM
This would be much easier to manage if you would put the "IsSelected" property on your row item in your collection rather than relying on the UI iterating. If you feel you must continue this path (and you shouldn't) and you are already using the grids multiple row select, you would just iterate through the RadGridView.SelectedItems.

Doing it through the UI / View is a bad pattern and will be more difficult to maintain. The RadGridView recycles rows and you can never be sure the RadGridView has all the rows you are interested in at one time. You will find it loads easier to implement and support if you do it through a ViewModel and allow each item in the collection to indicate whether it is selected or not, as an item becomes "selected" or "unselected" you could add and remove these items from your selected collection.

Paging is evil and a bad UI design pattern...but anyway, if you shared more details I would be happy to throw out some rough examples.

:)
Tags
GridView
Asked by
Joe
Top achievements
Rank 1
Answers by
Dimitrina
Telerik team
Joe
Top achievements
Rank 1
Tyree
Top achievements
Rank 2
Share this question
or