C# .NET - How can i change position of errortext (Means red icon elert) in datagridview?

Asked By Sejal Amin on 28-Jan-09 06:54 AM

 

hi,
I want to change position of erroricon(red elert symbol)  in datagridview column

Through Coding........
How can i achive this .........

Its urgent .........

Thanx in Advance...............

re - Web Star replied to Sejal Amin on 28-Jan-09 07:05 AM

if u wnat to put a red alert indicator in datagirdview column then u use the any symbol in header column and then u set hide and show of that indicator on depends upon the error comes in coding as u needed.

You need to use the Cellpainting and Cell_EndEdit events - [)ia6l0 iii replied to Sejal Amin on 28-Jan-09 09:29 AM

A sample from http://social.msdn.microsoft.com/Forums/en-US/winformsdatacontrols/thread/a44622c0-74e1-463b-97b9-27b87513747e/#page:2

is provided below.

private Point cellInError = new Point(-2, -2); 
private void dataGridView1_CellPainting(object sender, DataGridViewCellPaintingEventArgs e) 
{ 
if (dataGridView1.IsCurrentCellDirty && !String.IsNullOrEmpty(e.ErrorText)) 
{ // paint everything except error icon e.Paint(e.ClipBounds, DataGridViewPaintParts.All & ~(DataGridViewPaintParts.ErrorIcon)); 
// now move error icon over to fill in the padding space GraphicsContainer container = e.Graphics.BeginContainer(); e.Graphics.TranslateTransform(18, 0);
 e.Paint(this.ClientRectangle, DataGridViewPaintParts.ErrorIcon); e.Graphics.EndContainer(container);
 e.Handled = true; 
} 
} 
private void dataGridView1_CellEndEdit(object sender, DataGridViewCellEventArgs e)
 {
 if (dataGridView1[e.ColumnIndex, e.RowIndex].ErrorText != String.Empty)
 { DataGridViewCell cell = dataGridView1[e.ColumnIndex, e.RowIndex]; cell.ErrorText = String.Empty; cellInError = new Point(-2,-2); 
// restore padding for cell. This moves the editing control cell.Style.Padding = (Padding)cell.Tag; 
// hide and dispose tooltip 
if (errorTooltip != null)
 { 
errorTooltip.Hide(dataGridView1); errorTooltip.Dispose();
 errorTooltip = null; }
 }
 }

Strange. two people asking the same question - [)ia6l0 iii replied to Sejal Amin on 28-Jan-09 09:29 AM

Zach Fox replied to [)ia6l0 iii on 04-Feb-09 01:19 AM
Ha--I wonder if it's a homework assignment.
good one. - [)ia6l0 iii replied to Zach Fox on 04-Feb-09 01:37 AM
end of post