i use cell_painting event to draw Rectangle (in size of 3 cells). when i drag item from the listBox to the dataGridView the the Rectangle is blinking !!!
how i can fill Rectangle and draw string that it will not blink in the dataGridView ?
private List<Point> GeneralCourses = new List<Point>();
private void dataGridView1_DragDrop(object sender, DragEventArgs e)
{
Point p = this.dataGridView1.PointToClient(new Point(e.X, e.Y));
DataGridView.HitTestInfo info = this.dataGridView1.HitTest(p.X, p.Y);
if (info.RowIndex != -1 && info.ColumnIndex != -1)
{
Object value = (Object)e.Data.GetData(typeof(string));
this.dataGridView1.Rows[info.RowIndex].Cells[info.ColumnIndex].Value = value;
GeneralCourses.Add(new Point(info.RowIndex, info.ColumnIndex));
}
}
protected void dataGridView1_CellPainting(object sender, DataGridViewCellPaintingEventArgs e)
{
if (GeneralCourses.Contains(new Point(e.RowIndex, e.ColumnIndex)))
{
e.Handled = true;
dataGridView1.Invalidate();
Rectangle rectDest = Rectangle.Empty;
StringFormat sf = new StringFormat();
sf.Alignment = StringAlignment.Center;
sf.LineAlignment = StringAlignment.Center;
sf.Trimming = StringTrimming.EllipsisCharacter;
string str;
Pen p = new Pen(Color.Blue);
str = "string example";
rectDest = new Rectangle(e.CellBounds.X, e.CellBounds.Y, e.CellBounds.Size.Width * 3, e.CellBounds.Height);
e.Graphics.DrawRectangle(p, rectDest);
e.Graphics.FillRectangle(Brushes.LightBlue, rectDest);
e.Graphics.DrawString(str, new Font("Arial", 10, FontStyle.Regular), Brushes.Black, rectDest, sf);
p.Dispose();
sf.Dispose();
}
}