생각은 여기에 "셀"을 다시 그려 색과 텍스트 블록을 표시합니다. 이 때 폼을 표시이며 드롭 다운을 표시하는 것입니다 : 나는 색상을 선택DataGridView에서 CellPaint 이벤트 처리기 사용
후에 이상한 수행합니다
것은 지금은 모두 잘못된 것입니다. 다른 비트를 렌더링하려면 컨트롤 위로 마우스를 가져 가야합니다. 그냥 제대로 작동하지 않습니다.
내 처리기 :
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;
. 물론, 실제로 아무것도 그려지지 않습니다. 하지만 편집 된 기호로 왼쪽의 대부분의 셀이 흰색으로 표시되기까지 오랜 시간이 걸립니다. 그래서 그것의 메커니즘은 여전히 옳지 않습니다. 감사합니다.
제작 진행 : 나는이 방법은 내가 끝낼 제안하려고하면
! 그리드 라인을 포함 시키도록 조정할 수 있습니까? 정상 세포에서와 같이?
확실히 clipBounds 나 사용하지 마십시오 : 내가 잘못하고 필요한 구문의 일부를 가지고 있었다. – LarsTech
@LarsTech, 여기에서 알게되었습니다. http://stackoverflow.com/questions/7482534/custom-draw-of-datagridviewcomboboxcolumn –
답변을 다시 방문해야합니다. :-) – LarsTech