RadGridView: Getting Selected Cell within Selected Row

5 posts, 1 answers
  1. Alex
    Alex avatar
    3 posts
    Member since:
    Oct 2019

    Posted 14 Aug Link to this post

    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]

  2. Alex
    Alex avatar
    3 posts
    Member since:
    Oct 2019

    Posted 14 Aug in reply to Alex Link to this post

    Gah, found it. radGridView.CurrentCell is what I was looking for.
  3. Dess | Tech Support Engineer, Sr.
    Admin
    Dess | Tech Support Engineer, Sr.  avatar
    3900 posts

    Posted 17 Aug Link to this post

    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

  4. Alex
    Alex avatar
    3 posts
    Member since:
    Oct 2019

    Posted 17 Aug in reply to Dess | Tech Support Engineer, Sr. Link to this post

    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.

  5. Answer
    Dess | Tech Support Engineer, Sr.
    Admin
    Dess | Tech Support Engineer, Sr.  avatar
    3900 posts

    Posted 18 Aug Link to this post

    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

Back to Top