i use a DataView and RowFilter to display information in a winforms DataGrid
(c# devstudio win2kserver .net 1.037). I build a string RowFilterText which
contains the actual filter that i will apply (myDataView.RowFilter =
RowFilterText )
the problem arises when my filter returns 0 rows; instead of showing me an
empty datagrid, the program throws a "IndexOutOfRangeException. Additional
Information: No value at index 0" - and that's all the information it gives.
It was easy to find that the exception is generated DUE to the statement
myDataView.RowFilter = RowFilterText ;
(if i comment it, no exception is generated)
But I cannot understand WHERE is the exception generated:
the really big problem is that i cannot catch this exception; I have put the
statement in a try-catch block, but it doesn't catch the error! instead the
exception seems to come from my main function
[STAThread]
public static void Main()
{
Application.Run(new main_frm());
}
right after Application.Run;
How can I handle / trap this exception, why doesn't it occur at the
statement that assigns the filter??
Thanks
cristian
My tip: ALWAYS include a generic try... catch block in all
event-handling procedures. Then you'll see where the error
is coming from.
>.
>
thanks again
cristian
"Celia A" <noe...@thanks.com> wrote in message
news:50fb01c2f41d$a9b49bd0$3001...@phx.gbl...
I might have the simular problem as you have, but I catched the
following exception:
System.IndexOutOfRangeException: No value at index 0.
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&
boundingRect)
at System.Windows.Forms.DataGrid.PaintGrid(Graphics g, Rectangle
gridBounds)
at System.Windows.Forms.DataGrid.OnPaint(PaintEventArgs pe)
The way I catch it is from the main, this way you can catch any
exception from your application.
static void Main()
{
Thread.CurrentThread.ApartmentState = ApartmentState.STA;
try
{
Application.Run(new ApplicationContext(new Login()));
}
catch (Exception e)
{
Console.WriteLine("main thread: e: {0} e: {1}", e.StackTrace,
e);
switch (e.Message)
{
case "Security error.":
MessageBox.Show("Security e");
break;
default:
MessageBox.Show("Error: msg: " + e.Message + " stack: " +
e.StackTrace);
break;
}
}
}
The exception raised from my datagrid. The datasource is a dataview
and I also set the rowfilter. The exception happened when the last row
of the datagrid was removed. But the exception did not happened all
the time.
I would like to know how does your datagrid look like when the
exception raises from your application.
Regards,
Wendy