
После того, как я выбрал цвет, все становится странно:
[img]https://i .sstatic.net/oCyYZ.jpg[/img]
Теперь все не так. Мне нужно навести указатель мыши на элемент управления, чтобы отобразить другие биты. Просто работает неправильно.
Мой обработчик:
Код: Выделить всё
private void DataGridView1_CellPainting(object sender, DataGridViewCellPaintingEventArgs e)
{
if(e.ColumnIndex == 0 && e.RowIndex > 0)
{
e.PaintBackground(e.ClipBounds, true);
e.PaintContent(e.ClipBounds);
Graphics g = e.Graphics;
Color c = Color.Empty;
string s = "";
Brush br = SystemBrushes.WindowText;
Brush brBack;
Rectangle rDraw;
rDraw = e.ClipBounds;
rDraw.Inflate(-1, -1);
{
brBack = Brushes.White;
g.FillRectangle(brBack, e.ClipBounds);
}
try
{
ComboboxColorItem oColorItem = (ComboboxColorItem)((ComboBox)sender).SelectedItem;
s = oColorItem.ToString();
c = oColorItem.Value;
}
catch
{
s = "red";
c = Color.Red;
}
SolidBrush b = new SolidBrush(c);
Rectangle r = new Rectangle(e.ClipBounds.Left + 5, e.ClipBounds.Top + 3, 10, 10);
g.FillRectangle(b, r);
g.DrawRectangle(Pens.Black, r);
g.DrawString(s, Form.DefaultFont, Brushes.Black, e.ClipBounds.Left + 25, e.ClipBounds.Top + 1);
b.Dispose();
g.Dispose();
e.Handled = true;
}
}
}
Обновление:
Я попробовал это в событии CellPainting:
Код: Выделить всё
if(e.ColumnIndex == 0 && e.RowIndex > 0)
{
using (Graphics g = e.Graphics)
{
g.FillRectangle(Brushes.Aqua, e.CellBounds);
}
}
else
{
e.PaintBackground(e.CellBounds, true);
e.PaintContent(e.CellBounds);
}
e.Handled = true;
Спасибо.
Если я попробую предложенным способом, то в итоге получу:

Прогресс достигнут! Можем ли мы настроить его так, чтобы он по-прежнему включал линии сетки? Как в обычных ячейках?

Подробнее здесь: https://stackoverflow.com/questions/376 ... tagridview
Мобильная версия