kasdoffe
Well-known member
- Joined
- Aug 27, 2003
- Messages
- 57
I have a custom datagrid class that inherits from the System.Windows.Forms.Datagrid and Ive overridden the OnPaint event. I want to change the normal error icon that shows up in each grid cell that has an error with the new one I created.
The only problem is that after it paints my new image on top of the same location as the default icon, the OnPaint method executes again and again and again, looping forever. How do I get my image to be painted on top of the grid, in the exact cell location without the OnPaint infinitely looping?
Help please? Its got to be simple.
The only problem is that after it paints my new image on top of the same location as the default icon, the OnPaint method executes again and again and again, looping forever. How do I get my image to be painted on top of the grid, in the exact cell location without the OnPaint infinitely looping?
Help please? Its got to be simple.
Code:
protected override void OnPaint(PaintEventArgs e)
{
base.OnPaint(e);
if (this.DataTable!=null)
{
if (this.DataTable.HasErrors==true)
{
for (int i = 0; i<this.DataTable.Rows.Count; i++)
{
System.Data.DataColumn [] dc = this.DataTable.Rows[i].GetColumnsInError();
for (int j=0; j<dc.Length; j++)
{
this.CurrentCell = new DataGridCell(i,dc[j].Ordinal);
System.Drawing.Rectangle CellRect = this.GetCellBounds(this.CurrentCell);
System.Drawing.Image img = new Bitmap(@"C:\caution.gif");
System.Drawing.Bitmap b = new System.Drawing.Bitmap(img,14,14);
System.Drawing.Graphics g = this.CreateGraphics();
g.DrawImage(b,CellRect.Left+1,CellRect.Top+1);
}
}
}
}
}