[Mono-list] ListBox RemoveAt error.

Steve Harp steve at abelscreening.com
Mon Jan 12 10:29:06 EST 2009


Hi All,

 

I'm using a ListBox in a WinForms application under Linux to provide
status/progress messages to the user.  I'd like to limit the # of items in
the ListBox by deleting the first entry after some pre-defined limit has
been reached. 

 

If (ListBox1.Items.Count > myLimit)
{

  ListBox1.Items.RemoveAt(0);

}

 

Whenever the application hits the RemoveAt line, it throws an exception.

 

System.ArgumentOutOfRangeException: Argument is out of range.

Parameter name: GetItemRectangle index out of range.

  at System.Windows.Forms.ListBox.GetItemRectangle (Int32 index) [0x00167]
in
/usr/src/packages/BUILD/mono-2.0.1/mcs/class/Managed.Windows.Forms/System.Wi
ndows.Forms/ListBox.cs:847 

  at System.Windows.Forms.ListBox.GetItemDisplayRectangle (Int32 index,
Int32 first_displayble) [0x00008] in
/usr/src/packages/BUILD/mono-2.0.1/mcs/class/Managed.Windows.Forms/System.Wi
ndows.Forms/ListBox.cs:1286 

  at System.Windows.Forms.ListBox.InvalidateItem (Int32 index) [0x0000c] in
/usr/src/packages/BUILD/mono-2.0.1/mcs/class/Managed.Windows.Forms/System.Wi
ndows.Forms/ListBox.cs:1687 

  at (wrapper remoting-invoke-with-check)
System.Windows.Forms.ListBox:InvalidateItem (int)

  at System.Windows.Forms.ListBox+SelectedIndexCollection.ClearCore ()
[0x00030] in
/usr/src/packages/BUILD/mono-2.0.1/mcs/class/Managed.Windows.Forms/System.Wi
ndows.Forms/ListBox.cs:2699 

  at System.Windows.Forms.ListBox+SelectedIndexCollection.Clear () [0x00000]
in
/usr/src/packages/BUILD/mono-2.0.1/mcs/class/Managed.Windows.Forms/System.Wi
ndows.Forms/ListBox.cs:2687 

  at System.Windows.Forms.ListBox.ClearSelected () [0x00000] in
/usr/src/packages/BUILD/mono-2.0.1/mcs/class/Managed.Windows.Forms/System.Wi
ndows.Forms/ListBox.cs:716 

  at (wrapper remoting-invoke-with-check)
System.Windows.Forms.ListBox:ClearSelected ()

 

I have similar code running on Windows boxes and it works fine with MS .NET.
What is the correct way to do this with Mono?

 

Thanks,

Steve

 

-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.ximian.com/pipermail/mono-list/attachments/20090112/009a5379/attachment.html 


More information about the Mono-list mailing list