Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

RowFilter throws unusual exception

15 views
Skip to first unread message

Cristian Patapie

unread,
Mar 26, 2003, 5:03:03 PM3/26/03
to

Hello newsgroup, thanks for your time

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


Celia A

unread,
Mar 26, 2003, 11:59:35 PM3/26/03
to
Hi there,
When you set the filter the DataView raises its
ListChangedEvent event. That event is received by the grid
or other components on your form, outside the control of
your filtering procedure. These components raise their own
events, which you can handle. One of your event handlers
is probably causing the error.

My tip: ALWAYS include a generic try... catch block in all
event-handling procedures. Then you'll see where the error
is coming from.

>.
>

Cristian Patapie

unread,
Mar 27, 2003, 1:32:38 AM3/27/03
to

I'm not sure I got your point. Shoud I create now a function that handles
MyDataView.ListChangedEvent, and put a try-catch block in it? will it have
any effect, since that function won't have any actual code?? because
MyDataView.ListChangedEvent indeed has no event handler right now.

thanks again
cristian

"Celia A" <noe...@thanks.com> wrote in message
news:50fb01c2f41d$a9b49bd0$3001...@phx.gbl...

WendyC

unread,
Apr 4, 2003, 5:29:57 PM4/4/03
to
Cristian,

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

0 new messages