0

It's been some time since I have been coding in C# and in my current project I would like to create a table, which would allow for one column to display 2 filled up rectangles in various predefined colors in each of it's cells.

Is there a way to do this, keeping in mind that down the road: 1) the mouse-over trigger should also recognize each of the rectangles and 2) the user should be able to select the color of each of the rectangles.

?

I've seen some ideas for text fields, but they are hardly applicable here so if anyone can help, I would greatly appreciate it?

This is how I'd like it to look

Hoornet
  • 1,398
  • 3
  • 18
  • 30
  • 1
    Sure. did you look into the CellPainting event? You will also want to test which rectangle either by Rectangle.Contains(e.Location) or by testing e.Y in the maybe mouseclick event.. You could store the colors in a Tuple in the Cells' Tags. – TaW Apr 16 '19 at 14:00
  • @Taw Wow! Thank you! I will look into these options! DO you maybe know of some similar sample online that I could look at? – Hoornet Apr 17 '19 at 09:26
  • 1
    Here are a few examples: [Basic Cellpainting](https://stackoverflow.com/questions/26253110/cellpainting-checkbox-or-paint-part-of-the-cell/26253861#26253861), [More on the rules](https://stackoverflow.com/questions/51441885/text-overflows-for-custom-cell-painting-of-datagridview/51473848#51473848), [another simple example](https://stackoverflow.com/questions/54926247/display-header-text-after-cellpainting-event-in-winforms-datagridview/54926998#54926998)... – TaW Apr 17 '19 at 10:29
  • 1
    ..[a more involed one](https://stackoverflow.com/questions/32204732/c-sharp-winform-multiple-image-in-a-single-cell-datagirdviewimagecolumn/32205326#32205326) and finally one the many folks found either useful or [nice](https://stackoverflow.com/questions/30228710/how-can-i-create-a-footer-for-cell-in-datagridview/30234696#30234696).. - The real challenge will be storing the colors and defining the way the user can set those colors.. – TaW Apr 17 '19 at 10:30
  • thank you very much! Will study these today and tomorrow and look what I can do. – Hoornet Apr 17 '19 at 10:32

0 Answers0