<?xml version="1.0" encoding="utf-8"?><!-- generator="wordpress/1.5.1.3" -->
<rss version="2.0" 
	xmlns:content="http://purl.org/rss/1.0/modules/content/">
<channel>
	<title>Comments on: WinForms controls and the red X</title>
	<link>http://www.sturmnet.org/blog/archives/2005/03/23/red-x/</link>
	<description>General musings and programming stuff</description>
	<pubDate>Sat, 22 Nov 2008 13:35:45 +0000</pubDate>
	<generator>http://wordpress.org/?v=1.5.1.3</generator>

	<item>
		<title>by: alonesword</title>
		<link>http://www.sturmnet.org/blog/archives/2005/03/23/red-x/#comment-210714</link>
		<pubDate>Wed, 24 Sep 2008 02:13:44 +0000</pubDate>
		<guid>http://www.sturmnet.org/blog/archives/2005/03/23/red-x/#comment-210714</guid>
					<description>good.

i meet the same thing as Mehdy Mohajery.but the red X doesn't display on my computer except my pateners. and can't catch any exception.

&amp;#60;code&amp;#62;        
private void colConfigQuantity_BeforeCellPaint(object sender, ZTE.CCG.Common.ClientComponent.DataGrid.BeforeCellPaintEventArgs e)
{
		DataRowView drcur = ((DataView)e.DataSource.List)[e.RowNum]; // maybe throw exception here. i will check it soon.
		// check the data
		if(drcur.Row.Table.Columns.Contains(&amp;#34;ITEMENABLE&amp;#34;) &amp;#38;&amp;#38; (Convert.ToString(drcur[&amp;#34;ITEMENABLE&amp;#34;]) == NOUSING_STR &amp;#166;&amp;#166; Convert.ToString(drcur[&amp;#34;ITEMENABLE&amp;#34;]) == &amp;#34;N&amp;#34;))
		{
			e.ForeBrush = mBrushConfigQuantity;
		}
}
&amp;#60;/code&amp;#62;

After read the post,i decide to check the code again. 
thanks a lot.</description>
		<content:encoded><![CDATA[	<p>good.</p>
	<p>i meet the same thing as Mehdy Mohajery.but the red X doesn&#8217;t display on my computer except my pateners. and can&#8217;t catch any exception.</p>
	<p>&lt;code&gt;<br />
private void colConfigQuantity_BeforeCellPaint(object sender, ZTE.CCG.Common.ClientComponent.DataGrid.BeforeCellPaintEventArgs e)<br />
{<br />
		DataRowView drcur = ((DataView)e.DataSource.List)[e.RowNum]; // maybe throw exception here. i will check it soon.<br />
		// check the data<br />
		if(drcur.Row.Table.Columns.Contains(&quot;ITEMENABLE&quot;) &amp;&amp; (Convert.ToString(drcur[&quot;ITEMENABLE&quot;]) == NOUSING_STR || Convert.ToString(drcur[&quot;ITEMENABLE&quot;]) == &quot;N&quot;))<br />
		{<br />
			e.ForeBrush = mBrushConfigQuantity;<br />
		}<br />
}<br />
&lt;/code&gt;</p>
	<p>After read the post,i decide to check the code again.<br />
thanks a lot.
</p>
]]></content:encoded>
				</item>
	<item>
		<title>by: Smit Shah</title>
		<link>http://www.sturmnet.org/blog/archives/2005/03/23/red-x/#comment-58772</link>
		<pubDate>Wed, 25 Oct 2006 20:59:29 +0000</pubDate>
		<guid>http://www.sturmnet.org/blog/archives/2005/03/23/red-x/#comment-58772</guid>
					<description>---------------------------
Object reference not set to an instance of an object.
---------------------------
   at System.Data.DataView.GetRecord(Int32 recordIndex)

   at System.Data.DataView.IsOriginalVersion(Int32 index)

   at System.Data.DataRowView.GetColumnValue(DataColumn column)

   at System.Data.DataColumnPropertyDescriptor.GetValue(Object component)

   at System.Windows.Forms.DataGridColumnStyle.GetColumnValueAtRow(CurrencyManager source, Int32 rowNum)

   at System.Windows.Forms.DataGridTextBoxColumn.Paint(Graphics g, Rectangle bounds, CurrencyManager source, Int32 rowNum, Brush backBrush, Brush foreBrush, Boolean alignToRight)

   at System.Windows.Forms.DataGridRelationshipRow.PaintCellContents(Graphics g, Rectangle cellBounds, DataGridColumnStyle column, Brush backBr, Brush foreBrush, Boolean alignToRight)

   at System.Windows.Forms.DataGridRow.PaintData(Graphics g, Rectangle bounds, Int32 firstVisibleColumn, Int32 columnCount, Boolean alignToRight)

   at System.Windows.Forms.DataGridRelationshipRow.Paint(Graphics g, Rectangle bounds, Rectangle trueRowBounds, Int32 firstVisibleColumn, Int32 numVisibleColumns, Boolean alignToRight)

   at System.Windows.Forms.DataGrid.PaintRows(Graphics g, Rectangle&amp;#38; boundingRect)

   at System.Windows.Forms.DataGrid.PaintGrid(Graphics g, Rectangle gridBounds)

   at System.Windows.Forms.DataGrid.OnPaint(PaintEventArgs pe)

   at System.Windows.Forms.Control.PaintWithErrorHandling(PaintEventArgs e, Int16 layer, Boolean disposeEventArgs)

   at System.Windows.Forms.Control.WmPaint(Message&amp;#38; m)

   at System.Windows.Forms.Control.WndProc(Message&amp;#38; m)

   at System.Windows.Forms.ControlNativeWindow.OnMessage(Message&amp;#38; m)

   at System.Windows.Forms.ControlNativeWindow.WndProc(Message&amp;#38; m)

   at System.Windows.Forms.NativeWindow.DebuggableCallback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)

   at System.Windows.Forms.UnsafeNativeMethods.DispatchMessageW(MSG&amp;#38; msg)

   at System.Windows.Forms.ComponentManager.System.Windows.Forms.UnsafeNativeMethods+IMsoComponentManager.FPushMessageLoop(Int32 dwComponentID, Int32 reason, Int32 pvLoopData)

   at System.Windows.Forms.ThreadContext.RunMessageLoopInner(Int32 reason, ApplicationContext context)

   at System.Windows.Forms.ThreadContext.RunMessageLoop(Int32 reason, ApplicationContext context)

   at System.Windows.Forms.Application.Run(Form mainForm)

   at eBuilder.Apps.TransferManagerApp.modMain.main() in C:\VSS\TransferManager\TransferManagerApplication\modMain.vb:line 45
---------------------------
OK  
---------------------------




dvQueue = New DataView(modMain.objClsDSTMW.dsTransferManager.transferManagerFile, &amp;#34;fFileStatus&amp;#60;&amp;#62;'Success' and fFileStatus&amp;#60;&amp;#62;'Cancelled'&amp;#34;, &amp;#34;fFilePriority ASC&amp;#34;, DataViewRowState.CurrentRows)
        dgQueue.DataSource = dvQueue


the datagrid is bound to a dataset's datatable and teh table is updated via another thread in the process... this causes the above exception... the thread updates the dataset at times may be 100 times a second.. so hwo do I work arround this.

I tried your suggestion, but without success.

thanks
-smit.

pelase help</description>
		<content:encoded><![CDATA[	<p>&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;<br />
Object reference not set to an instance of an object.<br />
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;<br />
   at System.Data.DataView.GetRecord(Int32 recordIndex)</p>
	<p>   at System.Data.DataView.IsOriginalVersion(Int32 index)</p>
	<p>   at System.Data.DataRowView.GetColumnValue(DataColumn column)</p>
	<p>   at System.Data.DataColumnPropertyDescriptor.GetValue(Object component)</p>
	<p>   at System.Windows.Forms.DataGridColumnStyle.GetColumnValueAtRow(CurrencyManager source, Int32 rowNum)</p>
	<p>   at System.Windows.Forms.DataGridTextBoxColumn.Paint(Graphics g, Rectangle bounds, CurrencyManager source, Int32 rowNum, Brush backBrush, Brush foreBrush, Boolean alignToRight)</p>
	<p>   at System.Windows.Forms.DataGridRelationshipRow.PaintCellContents(Graphics g, Rectangle cellBounds, DataGridColumnStyle column, Brush backBr, Brush foreBrush, Boolean alignToRight)</p>
	<p>   at System.Windows.Forms.DataGridRow.PaintData(Graphics g, Rectangle bounds, Int32 firstVisibleColumn, Int32 columnCount, Boolean alignToRight)</p>
	<p>   at System.Windows.Forms.DataGridRelationshipRow.Paint(Graphics g, Rectangle bounds, Rectangle trueRowBounds, Int32 firstVisibleColumn, Int32 numVisibleColumns, Boolean alignToRight)</p>
	<p>   at System.Windows.Forms.DataGrid.PaintRows(Graphics g, Rectangle&amp; boundingRect)</p>
	<p>   at System.Windows.Forms.DataGrid.PaintGrid(Graphics g, Rectangle gridBounds)</p>
	<p>   at System.Windows.Forms.DataGrid.OnPaint(PaintEventArgs pe)</p>
	<p>   at System.Windows.Forms.Control.PaintWithErrorHandling(PaintEventArgs e, Int16 layer, Boolean disposeEventArgs)</p>
	<p>   at System.Windows.Forms.Control.WmPaint(Message&amp; m)</p>
	<p>   at System.Windows.Forms.Control.WndProc(Message&amp; m)</p>
	<p>   at System.Windows.Forms.ControlNativeWindow.OnMessage(Message&amp; m)</p>
	<p>   at System.Windows.Forms.ControlNativeWindow.WndProc(Message&amp; m)</p>
	<p>   at System.Windows.Forms.NativeWindow.DebuggableCallback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)</p>
	<p>   at System.Windows.Forms.UnsafeNativeMethods.DispatchMessageW(MSG&amp; msg)</p>
	<p>   at System.Windows.Forms.ComponentManager.System.Windows.Forms.UnsafeNativeMethods+IMsoComponentManager.FPushMessageLoop(Int32 dwComponentID, Int32 reason, Int32 pvLoopData)</p>
	<p>   at System.Windows.Forms.ThreadContext.RunMessageLoopInner(Int32 reason, ApplicationContext context)</p>
	<p>   at System.Windows.Forms.ThreadContext.RunMessageLoop(Int32 reason, ApplicationContext context)</p>
	<p>   at System.Windows.Forms.Application.Run(Form mainForm)</p>
	<p>   at eBuilder.Apps.TransferManagerApp.modMain.main() in C:\VSS\TransferManager\TransferManagerApplication\modMain.vb:line 45<br />
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;<br />
OK<br />
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;</p>
	<p>dvQueue = New DataView(modMain.objClsDSTMW.dsTransferManager.transferManagerFile, &quot;fFileStatus&lt;&gt;&#8217;Success&#8217; and fFileStatus&lt;&gt;&#8217;Cancelled&#8217;&quot;, &quot;fFilePriority ASC&quot;, DataViewRowState.CurrentRows)<br />
        dgQueue.DataSource = dvQueue</p>
	<p>the datagrid is bound to a dataset&#8217;s datatable and teh table is updated via another thread in the process&#8230; this causes the above exception&#8230; the thread updates the dataset at times may be 100 times a second.. so hwo do I work arround this.</p>
	<p>I tried your suggestion, but without success.</p>
	<p>thanks<br />
-smit.</p>
	<p>pelase help
</p>
]]></content:encoded>
				</item>
	<item>
		<title>by: Oliver Sturm</title>
		<link>http://www.sturmnet.org/blog/archives/2005/03/23/red-x/#comment-10987</link>
		<pubDate>Tue, 07 Feb 2006 20:53:47 +0000</pubDate>
		<guid>http://www.sturmnet.org/blog/archives/2005/03/23/red-x/#comment-10987</guid>
					<description>Well, obviously your code could easily throw an exception as soon as the type of o is one that can't be cast to a string. I would rewrite that section as 
  
&lt;pre language=&quot;c#&quot;&gt;
  string stringContent = o as string;
  if (stringContent != null) {
    if (stringContent == &amp;#34;Complete&amp;#34;)
       ...
    else if (stringContent == &amp;#34;Error&amp;#34;)
       ...
    else
       ...
  }
&lt;/pre&gt;

Looks nicer and can't go wrong. Now, as you're still catching everything in the outer try/catch, I still have no idea why that routine would throw an exception. I don't remember things as closely as I did when I wrote this post, maybe there are other interesting code paths due to the fact that you're using an overridden method instead of an event handler? I suggest you get Reflector and find out :-)</description>
		<content:encoded><![CDATA[	<p>Well, obviously your code could easily throw an exception as soon as the type of o is one that can&#8217;t be cast to a string. I would rewrite that section as </p>
	<pre language="c#">
  string stringContent = o as string;
  if (stringContent != null) {
    if (stringContent == &quot;Complete&quot;)
       ...
    else if (stringContent == &quot;Error&quot;)
       ...
    else
       ...
  }
</pre>
	<p>Looks nicer and can&#8217;t go wrong. Now, as you&#8217;re still catching everything in the outer try/catch, I still have no idea why that routine would throw an exception. I don&#8217;t remember things as closely as I did when I wrote this post, maybe there are other interesting code paths due to the fact that you&#8217;re using an overridden method instead of an event handler? I suggest you get Reflector and find out <img src='http://www.sturmnet.org/blog/wp-images/smilies/icon_smile.gif' alt=':-)' class='wp-smiley' />
</p>
]]></content:encoded>
				</item>
	<item>
		<title>by: Andrew</title>
		<link>http://www.sturmnet.org/blog/archives/2005/03/23/red-x/#comment-10950</link>
		<pubDate>Mon, 06 Feb 2006 15:27:48 +0000</pubDate>
		<guid>http://www.sturmnet.org/blog/archives/2005/03/23/red-x/#comment-10950</guid>
					<description>Hi, 

I have being seeing a &quot;red x&quot; appearing in place of a datagrid, but this is very rare.  I do have a custom column style, and am leaning towards its' overriden OnPaint() method as being the culprit.  The custom paint method is attempting to color the rows in the columnn based on the cell contents.

Wondering if you could point out any errors in the following method?  Thanks so much!

&lt;pre language=&quot;c#&quot;&gt;
protected override void Paint(System.Drawing.Graphics g, 
	System.Drawing.Rectangle bounds, System.Windows.Forms.CurrencyManager
	source, int rowNum, System.Drawing.Brush backBrush, System.Drawing.Brush 
	foreBrush, bool alignToRight) 

{
  // the idea is to conditionally set the foreBrush and/or backbrush 
  // depending upon some crireria on the cell value  
  // Here, we color anything that begins with a letter higher than 'F' 
  try
  { 
    object o = this.GetColumnValueAtRow(source, rowNum); 
    if( o != null) 
    { 
      if( ((string)o) == &amp;#34;Complete&amp;#34; )
      {
        backBrush = new SolidBrush(Color.Green); 
	foreBrush = new SolidBrush(Color.White);
      } 
      else if( ((string)o) == &amp;#34;Error&amp;#34; )
      {
	backBrush = new SolidBrush(Color.FromArgb(255, 128, 128));
      }
      else
      {
	backBrush = new SolidBrush(Color.White);
      }
    } 

    base.Paint(g, bounds, source, rowNum, backBrush, foreBrush, alignToRight);
  } 
  catch(Exception ex)
  { /* empty catch */ }
}
&lt;/pre&gt;</description>
		<content:encoded><![CDATA[	<p>Hi, </p>
	<p>I have being seeing a &#8220;red x&#8221; appearing in place of a datagrid, but this is very rare.  I do have a custom column style, and am leaning towards its&#8217; overriden OnPaint() method as being the culprit.  The custom paint method is attempting to color the rows in the columnn based on the cell contents.</p>
	<p>Wondering if you could point out any errors in the following method?  Thanks so much!</p>
	<pre language="c#">
protected override void Paint(System.Drawing.Graphics g,
	System.Drawing.Rectangle bounds, System.Windows.Forms.CurrencyManager
	source, int rowNum, System.Drawing.Brush backBrush, System.Drawing.Brush
	foreBrush, bool alignToRight) 
	
{
  // the idea is to conditionally set the foreBrush and/or backbrush
  // depending upon some crireria on the cell value
  // Here, we color anything that begins with a letter higher than 'F'
  try
  {
    object o = this.GetColumnValueAtRow(source, rowNum);
    if( o != null)
    {
      if( ((string)o) == &quot;Complete&quot; )
      {
        backBrush = new SolidBrush(Color.Green);
	foreBrush = new SolidBrush(Color.White);
      }
      else if( ((string)o) == &quot;Error&quot; )
      {
	backBrush = new SolidBrush(Color.FromArgb(255, 128, 128));
      }
      else
      {
	backBrush = new SolidBrush(Color.White);
      }
    } 
	
    base.Paint(g, bounds, source, rowNum, backBrush, foreBrush, alignToRight);
  }
  catch(Exception ex)
  { /* empty catch */ }
}
</pre>
]]></content:encoded>
				</item>
	<item>
		<title>by: Mehdy Mohajery</title>
		<link>http://www.sturmnet.org/blog/archives/2005/03/23/red-x/#comment-6388</link>
		<pubDate>Tue, 06 Dec 2005 11:34:20 +0000</pubDate>
		<guid>http://www.sturmnet.org/blog/archives/2005/03/23/red-x/#comment-6388</guid>
					<description>Hi,
   I have this problem when I reject changes to dataset of a datagrid.
   I set the .Visible property of the datagrid to false and after 
   changing data I set it to true back.
   this workaround fixed my datagrid RED X / RED Cross problem.

best RegardsZ
Mehdy Mohajery
--</description>
		<content:encoded><![CDATA[	<p>Hi,<br />
   I have this problem when I reject changes to dataset of a datagrid.<br />
   I set the .Visible property of the datagrid to false and after<br />
   changing data I set it to true back.<br />
   this workaround fixed my datagrid RED X / RED Cross problem.</p>
	<p>best RegardsZ<br />
Mehdy Mohajery<br />
&#8211;
</p>
]]></content:encoded>
				</item>
	<item>
		<title>by: Oliver Sturm</title>
		<link>http://www.sturmnet.org/blog/archives/2005/03/23/red-x/#comment-1992</link>
		<pubDate>Sun, 24 Jul 2005 09:39:55 +0000</pubDate>
		<guid>http://www.sturmnet.org/blog/archives/2005/03/23/red-x/#comment-1992</guid>
					<description>Hi Walter, nice to hear you found a solution. I think that the tool you are mentioning may be a good guess for the source of your problems. Thanks for keeping us updated!</description>
		<content:encoded><![CDATA[	<p>Hi Walter, nice to hear you found a solution. I think that the tool you are mentioning may be a good guess for the source of your problems. Thanks for keeping us updated!
</p>
]]></content:encoded>
				</item>
	<item>
		<title>by: Walter</title>
		<link>http://www.sturmnet.org/blog/archives/2005/03/23/red-x/#comment-1967</link>
		<pubDate>Sat, 23 Jul 2005 12:12:23 +0000</pubDate>
		<guid>http://www.sturmnet.org/blog/archives/2005/03/23/red-x/#comment-1967</guid>
					<description>Thanks for all your suggestions.

In the meantime I have implemented an application exception handler
that fetches all unhandled exceptions, including the ones that
lead to a red cross.

When this happens I try to automatically repaint all forms/controls. This
approach now works fine.

I know this is just a workaround, but when the &quot;Red X&quot; occurs there is none
of my code involved... The call stack often just shows System.* - classes.
Even worse, I only have to move windows across the screen and suddenly a 
&quot;Red X&quot; appears. In other situations its a 3rd party control that does
repainting etc. Nothing I can debug or fix here.

The only reason I can guess about is an old 3rd party tool we have to 
incorporate in our .NET Forms using the tricky and unsupported way of
using SetParent(). This is a bad thing, I know, but it's a *must*. And 
replacing that old tool with new .NET Forms will take a long time 
- but it will be done.

Thanks,
Walter</description>
		<content:encoded><![CDATA[	<p>Thanks for all your suggestions.</p>
	<p>In the meantime I have implemented an application exception handler<br />
that fetches all unhandled exceptions, including the ones that<br />
lead to a red cross.</p>
	<p>When this happens I try to automatically repaint all forms/controls. This<br />
approach now works fine.</p>
	<p>I know this is just a workaround, but when the &#8220;Red X&#8221; occurs there is none<br />
of my code involved&#8230; The call stack often just shows System.* - classes.<br />
Even worse, I only have to move windows across the screen and suddenly a<br />
&#8220;Red X&#8221; appears. In other situations its a 3rd party control that does<br />
repainting etc. Nothing I can debug or fix here.</p>
	<p>The only reason I can guess about is an old 3rd party tool we have to<br />
incorporate in our .NET Forms using the tricky and unsupported way of<br />
using SetParent(). This is a bad thing, I know, but it&#8217;s a *must*. And<br />
replacing that old tool with new .NET Forms will take a long time<br />
- but it will be done.</p>
	<p>Thanks,<br />
Walter
</p>
]]></content:encoded>
				</item>
	<item>
		<title>by: John Covalesky</title>
		<link>http://www.sturmnet.org/blog/archives/2005/03/23/red-x/#comment-1680</link>
		<pubDate>Mon, 11 Jul 2005 18:33:46 +0000</pubDate>
		<guid>http://www.sturmnet.org/blog/archives/2005/03/23/red-x/#comment-1680</guid>
					<description>Oliver is correct, many times there is a solution to this problem by modifying your own code.

It is important to track these down, because they can rear their head when the bug is reached by another route, not handled by MS code.
The trick to tracking these down is to subclass the failing control, override the OnPaint method,
and catch exception there -- print out stack trace.

This is why that works -- the OnPaint method is called by the .NET framework with a special method named something like PaintWithErrorHandling, which then calls OnPaint.

If you subclass, you can get stack traces of the issue, rather than the framework swallowing the whole thing.

Sample call stack
&lt;pre&gt;at System.Windows.Forms.CurrencyManager.get_Item(Int32 index)
   at System.Windows.Forms.DataGridRow.PaintHeader(Graphics g, Rectangle visualBounds, Boolean alignToRight, Boolean rowIsDirty)
   at System.Windows.Forms.DataGridRelationshipRow.PaintHeaderInside(Graphics g, Rectangle bounds, Brush backBr, Boolean alignToRight, Boolean isDirty)
   at System.Windows.Forms.DataGridRelationshipRow.PaintHeader(Graphics g, Rectangle bounds, Boolean alignToRight, Boolean isDirty)
   at System.Windows.Forms.DataGrid.PaintRows(Graphics g, Rectangle&amp;#38; boundingRect)
   at System.Windows.Forms.DataGrid.PaintGrid(Graphics g, Rectangle gridBounds)
   at System.Windows.Forms.DataGrid.OnPaint(PaintEventArgs pe)
&lt;/pre&gt;

sample OnPaint
&lt;pre language=&quot;c#&quot;&gt;
protected override void OnPaint( Grapics g )
{
  try
    {
        base.OnPaint(g);
    }
    catch( Exception e )
    {
        System.Console.Writeline( e.StackTrace);
    }

}
&lt;/pre&gt;</description>
		<content:encoded><![CDATA[	<p>Oliver is correct, many times there is a solution to this problem by modifying your own code.</p>
	<p>It is important to track these down, because they can rear their head when the bug is reached by another route, not handled by MS code.<br />
The trick to tracking these down is to subclass the failing control, override the OnPaint method,<br />
and catch exception there &#8212; print out stack trace.</p>
	<p>This is why that works &#8212; the OnPaint method is called by the .NET framework with a special method named something like PaintWithErrorHandling, which then calls OnPaint.</p>
	<p>If you subclass, you can get stack traces of the issue, rather than the framework swallowing the whole thing.</p>
	<p>Sample call stack</p>
	<pre>at System.Windows.Forms.CurrencyManager.get_Item(Int32 index)
   at System.Windows.Forms.DataGridRow.PaintHeader(Graphics g, Rectangle visualBounds, Boolean alignToRight, Boolean rowIsDirty)
   at System.Windows.Forms.DataGridRelationshipRow.PaintHeaderInside(Graphics g, Rectangle bounds, Brush backBr, Boolean alignToRight, Boolean isDirty)
   at System.Windows.Forms.DataGridRelationshipRow.PaintHeader(Graphics g, Rectangle bounds, Boolean alignToRight, Boolean isDirty)
   at System.Windows.Forms.DataGrid.PaintRows(Graphics g, Rectangle&amp; boundingRect)
   at System.Windows.Forms.DataGrid.PaintGrid(Graphics g, Rectangle gridBounds)
   at System.Windows.Forms.DataGrid.OnPaint(PaintEventArgs pe)
</pre>
	<p>sample OnPaint</p>
	<pre language="c#">
protected override void OnPaint( Grapics g )
{
  try
    {
        base.OnPaint(g);
    }
    catch( Exception e )
    {
        System.Console.Writeline( e.StackTrace);
    }
	
}
</pre>
]]></content:encoded>
				</item>
	<item>
		<title>by: Oliver Sturm</title>
		<link>http://www.sturmnet.org/blog/archives/2005/03/23/red-x/#comment-1278</link>
		<pubDate>Thu, 30 Jun 2005 08:37:26 +0000</pubDate>
		<guid>http://www.sturmnet.org/blog/archives/2005/03/23/red-x/#comment-1278</guid>
					<description>Walter - yes, there is a method &lt;code&gt;bool GetState(int flag)&lt;/code&gt; on the System.Windows.Forms.Control as well, so it's possible to query the information in the same way, using Reflection. If you're interested in that kind of thing, you should really get hold of Lutz Roeder's Reflector &lt;a href=&quot;http://www.aisto.com/roeder/dotnet&quot; rel=&quot;nofollow&quot;&gt;here&lt;/a&gt; and have a look at the implementation of these details.

The other thing, which maybe I shouldn't say, is this: if you were working for me, I'd tell you to go find that problem! As you say, it happens on your own controls as well, but even if it wasn't, the only real chance to get rid of these issues is to find an isolated test case that can reproduce them reliably. Sorry if this sounds harsh, but it's that simple: if you haven't found that test case yet, you haven't looked hard enough. Just my opinion, of course.</description>
		<content:encoded><![CDATA[	<p>Walter - yes, there is a method <code>bool GetState(int flag)</code> on the System.Windows.Forms.Control as well, so it&#8217;s possible to query the information in the same way, using Reflection. If you&#8217;re interested in that kind of thing, you should really get hold of Lutz Roeder&#8217;s Reflector <a href="http://www.aisto.com/roeder/dotnet">here</a> and have a look at the implementation of these details.</p>
	<p>The other thing, which maybe I shouldn&#8217;t say, is this: if you were working for me, I&#8217;d tell you to go find that problem! As you say, it happens on your own controls as well, but even if it wasn&#8217;t, the only real chance to get rid of these issues is to find an isolated test case that can reproduce them reliably. Sorry if this sounds harsh, but it&#8217;s that simple: if you haven&#8217;t found that test case yet, you haven&#8217;t looked hard enough. Just my opinion, of course.
</p>
]]></content:encoded>
				</item>
	<item>
		<title>by: Walter</title>
		<link>http://www.sturmnet.org/blog/archives/2005/03/23/red-x/#comment-1270</link>
		<pubDate>Wed, 29 Jun 2005 21:24:28 +0000</pubDate>
		<guid>http://www.sturmnet.org/blog/archives/2005/03/23/red-x/#comment-1270</guid>
					<description>Thanks for your answer. The problems are:

+ the Red X appears randomly, there is no clear workflow that produces it
+ it appears in 3rd party controls and/or on .NET controls
+ the 3rd party says, &quot;give me a sample&quot;... but, no way, see 1st remark

I'm thinking of fetching the exceptions and then try to &quot;correct&quot; the 
problem with your code (&quot;SetState&quot;). 

Is there a way to check the state of a control, to see if there is a Red X
drawn on it (&quot;GetState&quot;)? 

So I could check my controls and force a repaint on the broken ones.

Thanks for your help,
Walter</description>
		<content:encoded><![CDATA[	<p>Thanks for your answer. The problems are:</p>
	<p>+ the Red X appears randomly, there is no clear workflow that produces it<br />
+ it appears in 3rd party controls and/or on .NET controls<br />
+ the 3rd party says, &#8220;give me a sample&#8221;&#8230; but, no way, see 1st remark</p>
	<p>I&#8217;m thinking of fetching the exceptions and then try to &#8220;correct&#8221; the<br />
problem with your code (&#8221;SetState&#8221;). </p>
	<p>Is there a way to check the state of a control, to see if there is a Red X<br />
drawn on it (&#8221;GetState&#8221;)? </p>
	<p>So I could check my controls and force a repaint on the broken ones.</p>
	<p>Thanks for your help,<br />
Walter
</p>
]]></content:encoded>
				</item>
	<item>
		<title>by: Oliver Sturm</title>
		<link>http://www.sturmnet.org/blog/archives/2005/03/23/red-x/#comment-1268</link>
		<pubDate>Wed, 29 Jun 2005 19:08:12 +0000</pubDate>
		<guid>http://www.sturmnet.org/blog/archives/2005/03/23/red-x/#comment-1268</guid>
					<description>Hi Walter - no, there's no way to simply suppress the Red X completely. It's .NET's way of showing you that an error has occurred in a place where it influences the on-screen representation, and that this error wasn't caught. The only solution to this is to find the error and fix it, or to catch the resulting exception.

The question really is simple: does it (the X) appear on one of your own controls (in which case you have a bug in your drawing code) or does it appear on one of the third-party controls (in which case they have a bug in their drawing code)? You should try tracking that down, maybe also try isolating the issues by testing the controls that are used in your application in smaller test scenarios.

If you are able to scale your application down to a small test and you still see the problem, and you have no idea what it might be about... if you want, I'll have a look at it and see if I can figure anything out. But don't send me largish stuff with lots of external references, please!</description>
		<content:encoded><![CDATA[	<p>Hi Walter - no, there&#8217;s no way to simply suppress the Red X completely. It&#8217;s .NET&#8217;s way of showing you that an error has occurred in a place where it influences the on-screen representation, and that this error wasn&#8217;t caught. The only solution to this is to find the error and fix it, or to catch the resulting exception.</p>
	<p>The question really is simple: does it (the X) appear on one of your own controls (in which case you have a bug in your drawing code) or does it appear on one of the third-party controls (in which case they have a bug in their drawing code)? You should try tracking that down, maybe also try isolating the issues by testing the controls that are used in your application in smaller test scenarios.</p>
	<p>If you are able to scale your application down to a small test and you still see the problem, and you have no idea what it might be about&#8230; if you want, I&#8217;ll have a look at it and see if I can figure anything out. But don&#8217;t send me largish stuff with lots of external references, please!
</p>
]]></content:encoded>
				</item>
	<item>
		<title>by: Walter</title>
		<link>http://www.sturmnet.org/blog/archives/2005/03/23/red-x/#comment-1267</link>
		<pubDate>Wed, 29 Jun 2005 18:56:01 +0000</pubDate>
		<guid>http://www.sturmnet.org/blog/archives/2005/03/23/red-x/#comment-1267</guid>
					<description>Hi,
thanks for your insight to the &quot;Red X&quot; problem.

I have situations where I get the &quot;Red X&quot; very often, only minutes after the application starts.

I'm using 3rd-party products etc. and most of the time the Red X happens completely random and out of my code.

No exception handler will catch the exceptions, just a Red X appears and so far only a reboot is a solution - which is very, very bad.

So, do you know of a way to *avoid* the Red X? There should be an exception, ok, but the Red X destroys the UI and thats a bad thing.

Is it possible to configure .NET to *not* draw a Red X?

Any hints greatly appreciated!
Walter</description>
		<content:encoded><![CDATA[	<p>Hi,<br />
thanks for your insight to the &#8220;Red X&#8221; problem.</p>
	<p>I have situations where I get the &#8220;Red X&#8221; very often, only minutes after the application starts.</p>
	<p>I&#8217;m using 3rd-party products etc. and most of the time the Red X happens completely random and out of my code.</p>
	<p>No exception handler will catch the exceptions, just a Red X appears and so far only a reboot is a solution - which is very, very bad.</p>
	<p>So, do you know of a way to *avoid* the Red X? There should be an exception, ok, but the Red X destroys the UI and thats a bad thing.</p>
	<p>Is it possible to configure .NET to *not* draw a Red X?</p>
	<p>Any hints greatly appreciated!<br />
Walter
</p>
]]></content:encoded>
				</item>
	<item>
		<title>by: Oliver Sturm</title>
		<link>http://www.sturmnet.org/blog/archives/2005/03/23/red-x/#comment-580</link>
		<pubDate>Tue, 14 Jun 2005 18:20:53 +0000</pubDate>
		<guid>http://www.sturmnet.org/blog/archives/2005/03/23/red-x/#comment-580</guid>
					<description>Okay, now I understand what you're saying :-) I thought you were doing things the other way round, that's why I was referring to a third-party control. 

I've tried to do the same thing you're doing, but it seems to work fine for me. I'm sorry, but I have no idea which specific circumstances might cause an exception to show up in your case.</description>
		<content:encoded><![CDATA[	<p>Okay, now I understand what you&#8217;re saying <img src='http://www.sturmnet.org/blog/wp-images/smilies/icon_smile.gif' alt=':-)' class='wp-smiley' />  I thought you were doing things the other way round, that&#8217;s why I was referring to a third-party control. </p>
	<p>I&#8217;ve tried to do the same thing you&#8217;re doing, but it seems to work fine for me. I&#8217;m sorry, but I have no idea which specific circumstances might cause an exception to show up in your case.
</p>
]]></content:encoded>
				</item>
	<item>
		<title>by: Yiannis</title>
		<link>http://www.sturmnet.org/blog/archives/2005/03/23/red-x/#comment-559</link>
		<pubDate>Mon, 13 Jun 2005 15:39:04 +0000</pubDate>
		<guid>http://www.sturmnet.org/blog/archives/2005/03/23/red-x/#comment-559</guid>
					<description>The control is not a third party but the usual datagrid.
What i am doing is that i am creating a windows form and drag a datagrid into it.

If i add this form into a windows application and execute the app the grid opens fine (with no data).
When i am trying to open the form from a .NET Visio or excel Add-In i get the Red X.

Below is the source code from the visio add-in.

public void OnConnection(object application, Extensibility.ext_ConnectMode connectMode, object addInInst, ref System.Array custom)
		{
			
			applicationObject = application;
			addInInstance = addInInst;
			Form1 frm=new Form1();
			frm.ShowDialog();
		}

In form1 i have simply added the default datagrid with no additional code

Thanks in advance,
Yiannis



 </description>
		<content:encoded><![CDATA[	<p>The control is not a third party but the usual datagrid.<br />
What i am doing is that i am creating a windows form and drag a datagrid into it.</p>
	<p>If i add this form into a windows application and execute the app the grid opens fine (with no data).<br />
When i am trying to open the form from a .NET Visio or excel Add-In i get the Red X.</p>
	<p>Below is the source code from the visio add-in.</p>
	<p>public void OnConnection(object application, Extensibility.ext_ConnectMode connectMode, object addInInst, ref System.Array custom)<br />
		{</p>
	<p>			applicationObject = application;<br />
			addInInstance = addInInst;<br />
			Form1 frm=new Form1();<br />
			frm.ShowDialog();<br />
		}</p>
	<p>In form1 i have simply added the default datagrid with no additional code</p>
	<p>Thanks in advance,<br />
Yiannis
</p>
]]></content:encoded>
				</item>
	<item>
		<title>by: Oliver Sturm</title>
		<link>http://www.sturmnet.org/blog/archives/2005/03/23/red-x/#comment-558</link>
		<pubDate>Mon, 13 Jun 2005 15:11:44 +0000</pubDate>
		<guid>http://www.sturmnet.org/blog/archives/2005/03/23/red-x/#comment-558</guid>
					<description>Well, I think there may be not much you can do in this situation, because if the control in question is a third-party one, you might not be able to catch the exception that's responsible for the red X to show up. 

I'm also not getting the distinction you make: &quot;a form that contains a datagrid&quot; and &quot;using the same form from a Windows application&quot;? What's the difference? How were you &quot;using&quot; the form in the first case, where the X shows up?</description>
		<content:encoded><![CDATA[	<p>Well, I think there may be not much you can do in this situation, because if the control in question is a third-party one, you might not be able to catch the exception that&#8217;s responsible for the red X to show up. </p>
	<p>I&#8217;m also not getting the distinction you make: &#8220;a form that contains a datagrid&#8221; and &#8220;using the same form from a Windows application&#8221;? What&#8217;s the difference? How were you &#8220;using&#8221; the form in the first case, where the X shows up?
</p>
]]></content:encoded>
				</item>
	<item>
		<title>by: Yiannis</title>
		<link>http://www.sturmnet.org/blog/archives/2005/03/23/red-x/#comment-557</link>
		<pubDate>Mon, 13 Jun 2005 11:14:17 +0000</pubDate>
		<guid>http://www.sturmnet.org/blog/archives/2005/03/23/red-x/#comment-557</guid>
					<description>I am facing the same problem when trying to open a form that contains a datagrid from
a .NET Visio Add-In.The datagrid appears with a Red X inside.

If i use the same form but from a windows application the grid loads correctly.
Any ideas,suggestions will be most welcome...

Many Thanks</description>
		<content:encoded><![CDATA[	<p>I am facing the same problem when trying to open a form that contains a datagrid from<br />
a .NET Visio Add-In.The datagrid appears with a Red X inside.</p>
	<p>If i use the same form but from a windows application the grid loads correctly.<br />
Any ideas,suggestions will be most welcome&#8230;</p>
	<p>Many Thanks
</p>
]]></content:encoded>
				</item>
</channel>
</rss>
