PC Review


Reply
Thread Tools Rate Thread

Combobox.SelecedItem ArgumentOutOfRangeException

 
 
Nick Hoggard
Guest
Posts: n/a
 
      31st Aug 2004
Hi All,

I'm having a bit of trouble with a combo box at the moment. I'm building
in VB.NET CF and when I try to set the selected item of a ComboBox I am
getting an ArgumentOutOfRangeException thrown.

The exception I'm getting is the following. The strange part is that it
ignores the Try / Catch block and is just displayed in the IDE directly (in
the exception popup you would expect to see if you forgot the try / catch
block).

"An unhandled exception of type 'System.ArgumentOutOfRangeException'
occurred in mscorlib.dll'
Additional information: ArgumentOutOfRangeException

The line in question reads

cmb.SelectedItem = objSelectedItem

where objSelectedItem was just a pointer to the item I want to select.

My first thought was that the object simply wasn't in the combos data
source, so I checked with the following watch:

ctype(cmb.datasource, ArrayList).contains(objSelectedItem)

This watch came back as true, so the object is definitely in the data
source.

The datasource at this stage has been changed since the pointer to
objSelectedItem was created, but the object is still in the ArrayList and
has not been re-instantiated. The only reason the datasource has changed
was to remove one of the items from the ArrayList

E.g.

dim objSelectedItem as MyCustomType = ctype(cmd.selectedItem,
MyCustomType)
dim al as ArrayList = ctype(cmb.datasource, ArrayList)
al.remove(someOtherObject)
cmb.datasource = nothing
cmb.datasource = al
cmb.SelectedItem = objSelectedItem

I'm not sure if this is the tidiest way to do this, but apart for the
current bug I'm encountering it seems to work ok.

Any help with this would be greatly appreciated.

Thanks in advance

Nick Hoggard



 
Reply With Quote
 
 
 
 
Nick Hoggard
Guest
Posts: n/a
 
      31st Aug 2004
Just as a bit more followup information, this also seems to happen in some
instances when I use selectedinde

E.g.

cmb.SelectedIndex = -1

> I'm having a bit of trouble with a combo box at the moment. I'm building
> in VB.NET CF and when I try to set the selected item of a ComboBox I am
> getting an ArgumentOutOfRangeException thrown.
>
> The exception I'm getting is the following. The strange part is that it
> ignores the Try / Catch block and is just displayed in the IDE directly

(in
> the exception popup you would expect to see if you forgot the try / catch
> block).
>
> "An unhandled exception of type 'System.ArgumentOutOfRangeException'
> occurred in mscorlib.dll'
> Additional information: ArgumentOutOfRangeException
>
> The line in question reads
>
> cmb.SelectedItem = objSelectedItem
>
> where objSelectedItem was just a pointer to the item I want to select.
>
> My first thought was that the object simply wasn't in the combos data
> source, so I checked with the following watch:
>
> ctype(cmb.datasource, ArrayList).contains(objSelectedItem)
>
> This watch came back as true, so the object is definitely in the data
> source.
>
> The datasource at this stage has been changed since the pointer to
> objSelectedItem was created, but the object is still in the ArrayList and
> has not been re-instantiated. The only reason the datasource has changed
> was to remove one of the items from the ArrayList
>
> E.g.
>
> dim objSelectedItem as MyCustomType = ctype(cmd.selectedItem,
> MyCustomType)
> dim al as ArrayList = ctype(cmb.datasource, ArrayList)
> al.remove(someOtherObject)
> cmb.datasource = nothing
> cmb.datasource = al
> cmb.SelectedItem = objSelectedItem
>
> I'm not sure if this is the tidiest way to do this, but apart for the
> current bug I'm encountering it seems to work ok.
>
> Any help with this would be greatly appreciated.
>
> Thanks in advance
>
> Nick Hoggard
>
>
>



 
Reply With Quote
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
ArgumentOutOfRangeException shapper Microsoft C# .NET 4 27th Oct 2009 08:55 AM
ArgumentOutOfRangeException =?Utf-8?B?V2VzdGU=?= Microsoft C# .NET 1 13th Nov 2007 12:53 PM
Extending a ComboBox flexibility with the ComboBox.ObjectCollection - ArgumentOutOfRangeException Desmond Cassidy Microsoft Dot NET Framework Forms 1 5th Sep 2006 05:37 PM
Combobox.SelectedValue | ArgumentOutOfRangeException =?Utf-8?B?Tmljaw==?= Microsoft Dot NET 0 17th Jan 2006 09:00 AM
ArgumentOutOfRangeException Zahid Microsoft Dot NET Compact Framework 0 24th Sep 2003 11:15 AM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 01:49 AM.