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

RadGridView: Getting Selected Cell within Selected Row

4 Answers 883 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Alex
Top achievements
Rank 1
Alex asked on 14 Aug 2020, 08:16 PM

With a RadGridView component, how do I access the contents of a single cell within a row that is selected?

In the code behind, I can access the selected item, but the selection is always the whole row. Granted, this is not unexpected as I have the selection mode set to "Row" (intentionally so). However, when actually interacting with the grid, I can click and highlight individual cells within the row selected – I have to imagine, then, that I should be able to access the specific cell highlighted. To my surprise, I've found no way to accomplish this. Is there a way?

[for context, I want to give the user the ability to copy individual cell values to the clipboard, instead of copying the whole row of values, WITHOUT changing the selection mode]

4 Answers, 1 is accepted

Sort by
0
Alex
Top achievements
Rank 1
answered on 14 Aug 2020, 08:45 PM
Gah, found it. radGridView.CurrentCell is what I was looking for.
0
Dess | Tech Support Engineer, Principal
Telerik team
answered on 17 Aug 2020, 11:39 AM

Hi, Alex,

I am glad that you have found a suitable solution for your case. Please refer to the following help article which gives more information about accessing cells: https://docs.telerik.com/devtools/winforms/controls/gridview/cells/accessing-cells 

As to the copy behavior, I would like to note that since R1 2017 when you press Ctrl+C RadGridView copies the selected data considering the SelectionMode. If the SelectionMode property is set to FullRowSelect, pressing Ctrl+C will copy the entire row. If it is set to CellSelect only the selected cell will be copied when pressing Ctrl+C. Note that you can still copy just a single cell when the SelectionMode is set to FullRowSelect. It is necessary to select the desired cell and right click to open the context menu where you have "Copy" option.

Additional information about the clipboard operations is available here: https://docs.telerik.com/devtools/winforms/controls/gridview/copy-paste-cut 

I hope this information helps. If you need any further assistance please don't hesitate to contact me.  

Regards,
Dess | Tech Support Engineer, Sr.
Progress Telerik

0
Alex
Top achievements
Rank 1
answered on 17 Aug 2020, 02:12 PM

Hi Dess,

Thank you for your response. In my particular case, I need the selection mode to be the full row and using Ctrl+C is a necessity just because I'm already using a context menu for several other functions (+ copying from context menu is a little clunkier anyway). Fortunately, I'm able to do this by adding a handler for KeyDown events and setting the current cell's value onto the clipboard accordingly.

0
Accepted
Dess | Tech Support Engineer, Principal
Telerik team
answered on 18 Aug 2020, 08:14 AM

Hello, Alex,

I am glad that you have found a suitable solution for your case.

However, I would like to note that the MasterGridViewTemplate introduces two methods appropriate for customizing the Clipboard data: Copy and Paste. Their default logic can be customized. The following KB article demonstrates a sample approach how you can a custom MasterGridViewTemplate and override the Copy method in order to introduce any custom logic when copying data: https://www.telerik.com/support/kb/winforms/gridview/details/copy-paste-displaymember-for-gridviewcomboboxcolumn 

This sample approach may be also suitable for your scenario. 

Should you have further questions please let me know.

Regards,
Dess | Tech Support Engineer, Sr.
Progress Telerik

Tags
GridView
Asked by
Alex
Top achievements
Rank 1
Answers by
Alex
Top achievements
Rank 1
Dess | Tech Support Engineer, Principal
Telerik team
Share this question
or