Reputation: 1247
I have two DataGridView
, the first containing a list of users the other containing colors.
First DataGridView
(Users)
The second DataGridView
(Colors)
By selecting a cell from the first DataGridView
, the program allows you to associate a color with a user.
The association takes place using the right mouse button and selecting the color.
After selection, the user's cell becomes colored, of the selected color, using the BackGroundColor
property.
The problem now is that I have to allow the user to associate multiple colors with a user, so how can I visualize that the cell has been associated with multiple colors?
Do you have any graphic idea of how to accomplish this? Unfortunately, you can not associate more colors in a Cell
, the only thing you can do is use the gradient but it does not matter to me.
Upvotes: 2
Views: 67
Reputation: 1237
You could do this by accessing the 'CellPainting' event on the DataGridView.
private void dataGridView1_CellPainting(object sender, DataGridViewCellPaintingEventArgs e)
{
var temp = sender as DataGridView;
if (temp.ColumnCount > 0 && temp.RowCount > 0)
{
// get the first cell at (0, 0)
var cellposition = dataGridView1.GetCellDisplayRectangle(0, 0, false);
var xStart = cellposition.X;
var yStart = cellposition.Y;
var xEnd = xStart + cellposition.Width / 2;
var yEnd = yStart + cellposition.Height;
for (int i = yStart; i < yEnd; ++i)
{
e.Graphics.DrawLine(new Pen(Color.Black, 1), new Point(xStart, i), new Point(xEnd, i));
}
}
}
This example code shows you how to paint on the Cell 1 (i.e. Column 0, Row 0), you can use this example to extend to further cells.
Upvotes: 1