We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. Image for the cookie policy date
close icon

Changing cell contents at context menu location

Hi, I''m using a context menu on the grid control. I want an option of the context menu to allow the user to highlight the text in the cell under the context menu. I''ve followed the sample "CellCommentTips" that allows the user to paint an Excel like triangle in the top right hand corner of the grid using grid_CellDrawn and e.Graphics.FillPolygon. I have the context menu working properly. Can anyone tell me how to get a reference to the cell itself and change it''s background colour, or change the colour of the text in that cell please? Thanks.

3 Replies

AD Administrator Syncfusion Team July 6, 2004 10:37 PM UTC

What kind of grid are you using? If it is a GridDataBoundGrid, you cannot ''set'' the style properties of a single cell. Instead, you handle an event, and dynamically provide the style properties for the requested row and column. http://www.syncfusion.com/Support/article.aspx?id=560 So, in your context menu, you could set some Form variables to save the right-clicked cell''s row and col. Then in PrepareViewStyleInfo, you would test e.ColIndex and e.RowIndex to see if they matched the saved row and col of teh context menu. If they do, then you can set e.Style.BackColor and e.Style.TextColor to try to change the cell.


AD Administrator Syncfusion Team July 7, 2004 05:50 AM UTC

Sorry I should have specified - it''s the Syncfusion.Windows.Forms.Grid.GridControl.


AD Administrator Syncfusion Team July 7, 2004 06:31 AM UTC

Here is a little sample. It handles 2 sort of complications. One regards when the grid''s comtext menu is displayed versus when a cell control''s context menu is displayed. The sample does a little work to make both cases display the same menu. The other is a problem getting the row, col of the click. For some reason, Control.MousePosition is not working for me to get the proper right click (I suspect the Framework is tweaking this to display its popup). But this problem can be worked around by handling CurrentCellMoved and just tracking the focusRow and focusCol. (Depending on setting, you may need to add a grid.MouseDown handler to track this as well. The sampledoes not need this.) ContextMenu_7384.zip

Loader.
Live Chat Icon For mobile
Up arrow icon