By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
434,948 Members | 1,958 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 434,948 IT Pros & Developers. It's quick & easy.

Adding an item to a Checked List Box

P: n/a
Hello,

I am trying to add an item to a checked list box, like:

clbList.Items.add("Hello",true)

I get an error back:

Run-time exception thrown: System.ArgumentOutOfRangeException - Specified
argument was out of the range of valid values. Parameter name: '-1' is not a
valid value for index.

This doesn't make a lot of sense? Any ideas why this happens?

Regards
Simon Jefferies
Tools Programmer, Headfirst Productions
mailto:si****@headfirst.co.uk
-
Nov 20 '05 #1
Share this Question
Share on Google+
26 Replies


P: n/a
Simon,

* "Simon Jefferies" <si****@headfirst.co.uk> scripsit:
I am trying to add an item to a checked list box, like:

clbList.Items.add("Hello",true)

I get an error back:

Run-time exception thrown: System.ArgumentOutOfRangeException - Specified
argument was out of the range of valid values. Parameter name: '-1' is not a
valid value for index.

This doesn't make a lot of sense? Any ideas why this happens?


I am not able to repro that. Are you sure this line throws the
exception? Which version of .NET do you use?

--
Herfried K. Wagner [MVP]
<URL:http://dotnet.mvps.org/>
Nov 20 '05 #2

P: n/a
"Simon Jefferies" <si****@headfirst.co.uk> schrieb
Hello,

I am trying to add an item to a checked list box, like:

clbList.Items.add("Hello",true)

I get an error back:

Run-time exception thrown: System.ArgumentOutOfRangeException -
Specified argument was out of the range of valid values. Parameter
name: '-1' is not a valid value for index.

This doesn't make a lot of sense? Any ideas why this happens?


Can't repro the prob with VB 2003. Please show me the real line of code (the
above one isn't).
--
Armin

How to quote and why:
http://www.plig.net/nnq/nquote.html
http://www.netmeister.org/news/learn2quote.html

Nov 20 '05 #3

P: n/a
Yes, the line goes green and breaks on it.

I am using .NET 2003.

Regards
Simon Jefferies
Tools Programmer, Headfirst Productions
mailto:si****@headfirst.co.uk
-
"Herfried K. Wagner [MVP]" <hi***************@gmx.at> wrote in message
news:uY**************@TK2MSFTNGP11.phx.gbl...
Simon,

* "Simon Jefferies" <si****@headfirst.co.uk> scripsit:
I am trying to add an item to a checked list box, like:

clbList.Items.add("Hello",true)

I get an error back:

Run-time exception thrown: System.ArgumentOutOfRangeException - Specified
argument was out of the range of valid values. Parameter name: '-1' is
not a
valid value for index.

This doesn't make a lot of sense? Any ideas why this happens?


I am not able to repro that. Are you sure this line throws the
exception? Which version of .NET do you use?

--
Herfried K. Wagner [MVP]
<URL:http://dotnet.mvps.org/>

Nov 20 '05 #4

P: n/a
I'm running VB .NET 2003 too.

I'm trying with the line quoted just to get it to add something basic.

Regards
Simon Jefferies
Tools Programmer, Headfirst Productions
mailto:si****@headfirst.co.uk
-
"Armin Zingler" <az*******@freenet.de> wrote in message
news:40***********************@news.freenet.de...
"Simon Jefferies" <si****@headfirst.co.uk> schrieb
Hello,

I am trying to add an item to a checked list box, like:

clbList.Items.add("Hello",true)

I get an error back:

Run-time exception thrown: System.ArgumentOutOfRangeException -
Specified argument was out of the range of valid values. Parameter
name: '-1' is not a valid value for index.

This doesn't make a lot of sense? Any ideas why this happens?


Can't repro the prob with VB 2003. Please show me the real line of code
(the
above one isn't).
--
Armin

How to quote and why:
http://www.plig.net/nnq/nquote.html
http://www.netmeister.org/news/learn2quote.html

Nov 20 '05 #5

P: n/a
"Simon Jefferies" <si****@headfirst.co.uk> schrieb
I'm running VB .NET 2003 too.

I'm trying with the line quoted just to get it to add something
basic.


But "add" and "true" usually start with capital letters.

Can you post the callstack from your function call down to the function
throwing the exception?
--
Armin

Nov 20 '05 #6

P: n/a
Here's the callstack, the first line looks interesting...

system.windows.forms.dll!System.Windows.Forms.Chec kedListBox.SetItemCheckState(int
index = -1, System.Windows.Forms.CheckState value = Checked) + 0xbc bytes
system.windows.forms.dll!System.Windows.Forms.Chec kedListBox.ObjectCollection.Add(System.Object
item = "Hello", System.Windows.Forms.CheckState check = Checked) + 0xa3
bytes
system.windows.forms.dll!System.Windows.Forms.Chec kedListBox.ObjectCollection.Add(System.Object
item = "Hello", bool isChecked = true) + 0x38 bytes
hfsoundeditorplugin.dll!HfSoundEditorPlugin.frmSou ndEditorView.DisplayWaveFilesForSoundBank()
Line 725 + 0x2b bytes Basic hfsoundeditorplugin.dll!HfSoundEditorPlugin.frmSou ndEditorView.DisplaySoundBankProperties()
Line 707 + 0xa bytes Basic
hfsoundeditorplugin.dll!HfSoundEditorPlugin.frmSou ndEditorView.tvwMain_AfterSelect(Object
sender = {System.Windows.Forms.TreeView},
System.Windows.Forms.TreeViewEventArgs e =
{System.Windows.Forms.TreeViewEventArgs}) Line 622 + 0xa bytes Basic
system.windows.forms.dll!System.Windows.Forms.Tree View.OnAfterSelect(System.Windows.Forms.TreeViewEv entArgs
e = {System.Windows.Forms.TreeViewEventArgs}) + 0x23 bytes
system.windows.forms.dll!System.Windows.Forms.Tree View.TvnSelected(System.Windows.Forms.NativeMethod s.NMTREEVIEW*
nmtv = 1237196) + 0x9c bytes
system.windows.forms.dll!System.Windows.Forms.Tree View.WmNotify(System.Windows.Forms.Message
m = {System.Windows.Forms.Message}) + 0x137 bytes
system.windows.forms.dll!System.Windows.Forms.Tree View.WndProc(System.Windows.Forms.Message
m = {System.Windows.Forms.Message}) + 0x8c bytes
system.windows.forms.dll!ControlNativeWindow.OnMes sage(System.Windows.Forms.Message
m = {System.Windows.Forms.Message}) + 0x19 bytes
system.windows.forms.dll!ControlNativeWindow.WndPr oc(System.Windows.Forms.Message
m = {System.Windows.Forms.Message}) + 0xda bytes
system.windows.forms.dll!System.Windows.Forms.Nati veWindow.DebuggableCallback(int
hWnd = 24578450, int msg = 8270, int wparam = 24578450, int lparam =
1237196) + 0x39 bytes
user32.dll!77d8857a()
user32.dll!77d8867b()
user32.dll!77d89363()
user32.dll!77d893cb()
system.windows.forms.dll!System.Windows.Forms.Cont rol.SendMessage(int msg
= 8270, int wparam = 24578450, int lparam = 1237196) + 0x40 bytes
system.windows.forms.dll!System.Windows.Forms.Cont rol.ReflectMessageInternal(int
hWnd = 24578450, System.Windows.Forms.Message m =
{System.Windows.Forms.Message}) + 0x78 bytes
system.windows.forms.dll!System.Windows.Forms.Cont rol.WmNotify(System.Windows.Forms.Message
m = {System.Windows.Forms.Message}) + 0x35 bytes
system.windows.forms.dll!System.Windows.Forms.Cont rol.WndProc(System.Windows.Forms.Message
m = {System.Windows.Forms.Message}) + 0x662 bytes
system.windows.forms.dll!System.Windows.Forms.Grou pBox.WndProc(System.Windows.Forms.Message
m = {System.Windows.Forms.Message}) + 0x6c bytes
system.windows.forms.dll!ControlNativeWindow.OnMes sage(System.Windows.Forms.Message
m = {System.Windows.Forms.Message}) + 0x19 bytes
system.windows.forms.dll!ControlNativeWindow.WndPr oc(System.Windows.Forms.Message
m = {System.Windows.Forms.Message}) + 0xda bytes
system.windows.forms.dll!System.Windows.Forms.Nati veWindow.DebuggableCallback(int
hWnd = 21432856, int msg = 78, int wparam = 24578450, int lparam = 1237196)
+ 0x39 bytes
user32.dll!77d8857a()
user32.dll!77d8867b()
user32.dll!77d89363()
user32.dll!77d893cb()
comctl32.dll!4d6daf3c()
comctl32.dll!4d6f6cb7()
comctl32.dll!4d6f8fe2()
comctl32.dll!4d6fa864()
user32.dll!77d8857a()
user32.dll!77d8867b()
user32.dll!77d8acba()
user32.dll!77d8ace0()
system.windows.forms.dll!System.Windows.Forms.Nati veWindow.DefWndProc(System.Windows.Forms.Message
m = {System.Windows.Forms.Message}) + 0xc2 bytes
system.windows.forms.dll!System.Windows.Forms.Cont rol.DefWndProc(System.Windows.Forms.Message
m = {System.Windows.Forms.Message}) + 0x19 bytes
system.windows.forms.dll!System.Windows.Forms.Cont rol.WndProc(System.Windows.Forms.Message
m = {System.Windows.Forms.Message}) + 0x9f5 bytes
system.windows.forms.dll!System.Windows.Forms.Tree View.WndProc(System.Windows.Forms.Message
m = {System.Windows.Forms.Message}) + 0x61c bytes
system.windows.forms.dll!ControlNativeWindow.OnMes sage(System.Windows.Forms.Message
m = {System.Windows.Forms.Message}) + 0x19 bytes
system.windows.forms.dll!ControlNativeWindow.WndPr oc(System.Windows.Forms.Message
m = {System.Windows.Forms.Message}) + 0xda bytes
system.windows.forms.dll!System.Windows.Forms.Nati veWindow.DebuggableCallback(int
hWnd = 24578450, int msg = 4363, int wparam = 9, int lparam = 1856120) +
0x39 bytes
user32.dll!77d8857a()
user32.dll!77d8867b()
user32.dll!77d89363()
user32.dll!77d893cb()
system.windows.forms.dll!System.Windows.Forms.Cont rol.SendMessage(int msg
= 4363, int wparam = 9, int lparam = 1856120) + 0x5b bytes
system.windows.forms.dll!System.Windows.Forms.Tree View.set_SelectedNode(System.Windows.Forms.TreeNod e
value = {Text="Unnamed"}) + 0x61 bytes
hfsoundeditorplugin.dll!HfSoundEditorPlugin.frmSou ndEditorView.AddBankToTree(HfSoundEditorPlugin.Sou ndBank
Bank = {HfSoundEditorPlugin.SoundBank}) Line 564 + 0x18 bytes Basic
hfsoundeditorplugin.dll!HfSoundEditorPlugin.frmSou ndEditorView.itmAddSoundBank_Click(Object
sender = {System.Windows.Forms.MenuItem}, System.EventArgs e =
{System.EventArgs}) Line 646 + 0xd bytes Basic
system.windows.forms.dll!System.Windows.Forms.Menu Item.OnClick(System.EventArgs
e = {System.EventArgs}) + 0x8f bytes
system.windows.forms.dll!MenuItemData.Execute() + 0x1e bytes
system.windows.forms.dll!System.Windows.Forms.Comm and.Invoke() + 0x4c
bytes
system.windows.forms.dll!System.Windows.Forms.Comm and.DispatchID(int id =
289) + 0x2c bytes
system.windows.forms.dll!System.Windows.Forms.Cont rol.WmCommand(System.Windows.Forms.Message
m = {System.Windows.Forms.Message}) + 0x4a bytes
system.windows.forms.dll!System.Windows.Forms.Cont rol.WndProc(System.Windows.Forms.Message
m = {System.Windows.Forms.Message}) + 0x238 bytes
system.windows.forms.dll!System.Windows.Forms.Tree View.WndProc(System.Windows.Forms.Message
m = {System.Windows.Forms.Message}) + 0x61c bytes
system.windows.forms.dll!ControlNativeWindow.OnMes sage(System.Windows.Forms.Message
m = {System.Windows.Forms.Message}) + 0x19 bytes
system.windows.forms.dll!ControlNativeWindow.WndPr oc(System.Windows.Forms.Message
m = {System.Windows.Forms.Message}) + 0xda bytes
system.windows.forms.dll!System.Windows.Forms.Nati veWindow.DebuggableCallback(int
hWnd = 24578450, int msg = 273, int wparam = 289, int lparam = 0) + 0x39
bytes
user32.dll!77d8857a()
user32.dll!77d8867b()
user32.dll!77d88ec4()
user32.dll!77d88f4d()
system.windows.forms.dll!System.Windows.Forms.Appl ication.ComponentManager.System.Windows.Forms.Unsa feNativeMethods+IMsoComponentManager.FPushMessageL oop(int
dwComponentID = 3, int reason = -1, int pvLoopData = 0) + 0x2fb bytes
system.windows.forms.dll!ThreadContext.RunMessageL oopInner(int reason
= -1, System.Windows.Forms.ApplicationContext context =
{System.Windows.Forms.ApplicationContext}) + 0x1db bytes
system.windows.forms.dll!ThreadContext.RunMessageL oop(int reason = -1,
System.Windows.Forms.ApplicationContext context =
{System.Windows.Forms.ApplicationContext}) + 0x4f bytes
system.windows.forms.dll!System.Windows.Forms.Appl ication.Run(System.Windows.Forms.Form
mainForm = {HfToolFramework.frmMain}) + 0x35 bytes
HfToolFramework.exe!HfToolFramework.frmMain.Main() Line 26 + 0x1d bytes
Basic

Regards
Simon Jefferies
Tools Programmer, Headfirst Productions
mailto:si****@headfirst.co.uk
www.headfirst.co.uk www.callofcthulhu.com
-
"Armin Zingler" <az*******@freenet.de> wrote in message
news:40***********************@news.freenet.de... "Simon Jefferies" <si****@headfirst.co.uk> schrieb
I'm running VB .NET 2003 too.

I'm trying with the line quoted just to get it to add something
basic.


But "add" and "true" usually start with capital letters.

Can you post the callstack from your function call down to the function
throwing the exception?
--
Armin

Nov 20 '05 #7

P: n/a
"Simon Jefferies" <si****@headfirst.co.uk> schrieb
Here's the callstack, the first line looks interesting...
system.windows.forms.dll!System.Windows.Forms.Chec kedListBox.SetItemCheckSta
te(int index = -1, System.Windows.Forms.CheckState value = Checked) + 0xbc
bytes

system.windows.forms.dll!System.Windows.Forms.Chec kedListBox.ObjectCollectio
n.Add(System.Object item = "Hello", System.Windows.Forms.CheckState check = Checked) +
0xa3 bytes

system.windows.forms.dll!System.Windows.Forms.Chec kedListBox.ObjectCollectio
n.Add(System.Object item = "Hello", bool isChecked = true) + 0x38 bytes


Yes, looks interesting. Tried to repro it again and to find the reason (IL
code) but I failed, sorry. Maybe Herfried will find out more.
--
Armin

Nov 20 '05 #8

P: n/a
* "Simon Jefferies" <si****@headfirst.co.uk> scripsit:
I'm running VB .NET 2003 too.

I'm trying with the line quoted just to get it to add something basic.


Enclose the line in a 'Try...Catch':

\\\
Try
Me.CheckedListBox...
Catch
End Try
///

Is the exception still thrown? If yes, it's not caused by the line!

--
Herfried K. Wagner [MVP]
<URL:http://dotnet.mvps.org/>
Nov 20 '05 #9

P: n/a
* "Armin Zingler" <az*******@freenet.de> scripsit:
Yes, looks interesting. Tried to repro it again and to find the reason (IL
code) but I failed, sorry. Maybe Herfried will find out more.


I am not able to repro it on VB.NET 2002 and VB.NET 2003. Mhm...

--
Herfried K. Wagner [MVP]
<URL:http://dotnet.mvps.org/>
Nov 20 '05 #10

P: n/a
I've changed my code to:

clbWaves.BeginUpdate()
clbWaves.Items.Clear()
Try
clbWaves.Items.Add("Hello", True)
Catch ex As Exception
End Try

clbWaves.EndUpdate()

The Catch statement is called with the Out of range exception.

Regards
Simon Jefferies
Tools Programmer, Headfirst Productions
mailto:si****@headfirst.co.uk
www.headfirst.co.uk www.callofcthulhu.com
-
"Herfried K. Wagner [MVP]" <hi***************@gmx.at> wrote in message
news:OF**************@TK2MSFTNGP11.phx.gbl...
* "Simon Jefferies" <si****@headfirst.co.uk> scripsit:
I'm running VB .NET 2003 too.

I'm trying with the line quoted just to get it to add something basic.


Enclose the line in a 'Try...Catch':

\\\
Try
Me.CheckedListBox...
Catch
End Try
///

Is the exception still thrown? If yes, it's not caused by the line!

--
Herfried K. Wagner [MVP]
<URL:http://dotnet.mvps.org/>

Nov 20 '05 #11

P: n/a
Simon,

* "Simon Jefferies" <si****@headfirst.co.uk> scripsit:
clbWaves.BeginUpdate()
clbWaves.Items.Clear()
Try
clbWaves.Items.Add("Hello", True)
Catch ex As Exception
End Try

clbWaves.EndUpdate()

The Catch statement is called with the Out of range exception.


Does the exception occur if you skip the 'Clear', 'BeginUpdate', and
'EndUpdate'? Are you sure you are performing the operation in the main
GUI thread?

--
Herfried K. Wagner [MVP]
<URL:http://dotnet.mvps.org/>
Nov 20 '05 #12

P: n/a
I don't get an exception when I comment out the BeginUpdate, Clear and
EndUpdate.

I put back in the Clear() and its still working, so it means BeginUpdate()
or EndUpdate() or both causes this problem?

Yes, I am performing this in the main application thread.

Why would this happen?

--
Regards
Simon Jefferies
Tools Programmer, Headfirst Productions
mailto:si****@headfirst.co.uk
www.headfirst.co.uk www.callofcthulhu.com
-
"Herfried K. Wagner [MVP]" <hi***************@gmx.at> wrote in message
news:O1**************@TK2MSFTNGP10.phx.gbl...
Simon,

* "Simon Jefferies" <si****@headfirst.co.uk> scripsit:
clbWaves.BeginUpdate()
clbWaves.Items.Clear()
Try
clbWaves.Items.Add("Hello", True)
Catch ex As Exception
End Try

clbWaves.EndUpdate()

The Catch statement is called with the Out of range exception.


Does the exception occur if you skip the 'Clear', 'BeginUpdate', and
'EndUpdate'? Are you sure you are performing the operation in the main
GUI thread?

--
Herfried K. Wagner [MVP]
<URL:http://dotnet.mvps.org/>

Nov 20 '05 #13

P: n/a
* "Simon Jefferies" <si****@headfirst.co.uk> scripsit:
I don't get an exception when I comment out the BeginUpdate, Clear and
EndUpdate.

I put back in the Clear() and its still working, so it means BeginUpdate()
or EndUpdate() or both causes this problem?

Yes, I am performing this in the main application thread.


I currently only have access to VB.NET 2002, there I am not able to
repro the "bug".

--
Herfried K. Wagner [MVP]
<URL:http://dotnet.mvps.org/>
Nov 20 '05 #14

P: n/a
Hi, Simon

I can't get it to repro here either.

What happens when you start a new project, add a checked list box & a
button, and put your code in the button's click event? If that works,
there is probably something wrong in your form or project files. Have you
edited the code in the Windows Form Designer generated code section? That
could be the culpret. If the simple project fails, please zip up the
simple project and attach it to a post. That will give us something real
to play with.

Hope this helps,

John Eikanger
Microsoft Developer Support

This posting is provided “AS IS” with no warranties, and confers no rights.
--------------------
| From: "Simon Jefferies" <si****@headfirst.co.uk>
| Subject: Re: Adding an item to a Checked List Box
| Date: Thu, 15 Apr 2004 15:57:44 +0100
| X-Tomcat-NG: microsoft.public.dotnet.languages.vb
|
| I don't get an exception when I comment out the BeginUpdate, Clear and
| EndUpdate.
|
| I put back in the Clear() and its still working, so it means
BeginUpdate()
| or EndUpdate() or both causes this problem?
|
| Yes, I am performing this in the main application thread.
|
| Why would this happen?
|
| --
| Regards
| Simon Jefferies
| Tools Programmer, Headfirst Productions
| mailto:si****@headfirst.co.uk
| www.headfirst.co.uk www.callofcthulhu.com
| -
| "Herfried K. Wagner [MVP]" <hi***************@gmx.at> wrote in message
| news:O1**************@TK2MSFTNGP10.phx.gbl...
| > Simon,
| >
| > * "Simon Jefferies" <si****@headfirst.co.uk> scripsit:
| >> clbWaves.BeginUpdate()
| >> clbWaves.Items.Clear()
| >> Try
| >> clbWaves.Items.Add("Hello", True)
| >> Catch ex As Exception
| >> End Try
| >>
| >> clbWaves.EndUpdate()
| >>
| >> The Catch statement is called with the Out of range exception.
| >
| > Does the exception occur if you skip the 'Clear', 'BeginUpdate', and
| > 'EndUpdate'? Are you sure you are performing the operation in the main
| > GUI thread?
| >
| > --
| > Herfried K. Wagner [MVP]
| > <URL:http://dotnet.mvps.org/>
|
|
|

Nov 20 '05 #15

P: n/a
Thanks for your reply,

When I created a new project it worked! Mmmm...

I haven't touched the Windows Form designer generated code section.

Any ideas on what to try next?

Regards
Simon Jefferies
Tools Programmer, Headfirst Productions
mailto:si****@headfirst.co.uk
www.headfirst.co.uk www.callofcthulhu.com
-
"John Eikanger [MSFT]" <jo****@online.microsoft.com> wrote in message
news:J6**************@cpmsftngxa06.phx.gbl...
Hi, Simon

I can't get it to repro here either.

What happens when you start a new project, add a checked list box & a
button, and put your code in the button's click event? If that works,
there is probably something wrong in your form or project files. Have you
edited the code in the Windows Form Designer generated code section? That
could be the culpret. If the simple project fails, please zip up the
simple project and attach it to a post. That will give us something real
to play with.

Hope this helps,

John Eikanger
Microsoft Developer Support

This posting is provided "AS IS" with no warranties, and confers no
rights.
--------------------
| From: "Simon Jefferies" <si****@headfirst.co.uk>
| Subject: Re: Adding an item to a Checked List Box
| Date: Thu, 15 Apr 2004 15:57:44 +0100
| X-Tomcat-NG: microsoft.public.dotnet.languages.vb
|
| I don't get an exception when I comment out the BeginUpdate, Clear and
| EndUpdate.
|
| I put back in the Clear() and its still working, so it means
BeginUpdate()
| or EndUpdate() or both causes this problem?
|
| Yes, I am performing this in the main application thread.
|
| Why would this happen?
|
| --
| Regards
| Simon Jefferies
| Tools Programmer, Headfirst Productions
| mailto:si****@headfirst.co.uk
| www.headfirst.co.uk www.callofcthulhu.com
| -
| "Herfried K. Wagner [MVP]" <hi***************@gmx.at> wrote in message
| news:O1**************@TK2MSFTNGP10.phx.gbl...
| > Simon,
| >
| > * "Simon Jefferies" <si****@headfirst.co.uk> scripsit:
| >> clbWaves.BeginUpdate()
| >> clbWaves.Items.Clear()
| >> Try
| >> clbWaves.Items.Add("Hello", True)
| >> Catch ex As Exception
| >> End Try
| >>
| >> clbWaves.EndUpdate()
| >>
| >> The Catch statement is called with the Out of range exception.
| >
| > Does the exception occur if you skip the 'Clear', 'BeginUpdate', and
| > 'EndUpdate'? Are you sure you are performing the operation in the
main
| > GUI thread?
| >
| > --
| > Herfried K. Wagner [MVP]
| > <URL:http://dotnet.mvps.org/>
|
|
|

Nov 20 '05 #16

P: n/a
Just to make sure the code is in the right place.
Can you put the code behind a command button and try it. should work fine..
Nov 20 '05 #17

P: n/a
Hello,

I've put the code behind a command button to perform the following:

clbWaves.BeginUpdate()
clbWaves.Items.Clear()
clbWaves.Items.Add("Hello", True)
clbWaves.EndUpdate()

and it still comes up with the exception...

Regards
Simon Jefferies
Tools Programmer, Headfirst Productions
mailto:si****@headfirst.co.uk
www.headfirst.co.uk www.callofcthulhu.com
-
"adamz5" <ad****@hotmail.com> wrote in message
news:40**************************@posting.google.c om...
Just to make sure the code is in the right place.
Can you put the code behind a command button and try it. should work
fine..

Nov 20 '05 #18

P: n/a
"Simon Jefferies" <si****@headfirst.co.uk> schrieb
Hello,

I've put the code behind a command button to perform the
following:

clbWaves.BeginUpdate()
clbWaves.Items.Clear()
clbWaves.Items.Add("Hello", True)
clbWaves.EndUpdate()

and it still comes up with the exception...


Could you please post all the code in the "Windos Form designer.." region
that uses clbWaves?
--
Armin

How to quote and why:
http://www.plig.net/nnq/nquote.html
http://www.netmeister.org/news/learn2quote.html

Nov 20 '05 #19

P: n/a
> I am trying to add an item to a checked list box, like:

clbList.Items.add("Hello",true)

I get an error back:

Run-time exception thrown: System.ArgumentOutOfRangeException - Specified
argument was out of the range of valid values. Parameter name: '-1' is not a
valid value for index.


true is a boolean but its integer representation is -1.
It maybe that this suggests that the 2nd parameter was expecting an integer?

Jonathan
Nov 20 '05 #20

P: n/a
Hello,

I've just double-checked the 2nd parameter and it is "IsChecked" and it
requires a boolean.

Regards
Simon Jefferies
Tools Programmer, Headfirst Productions
mailto:si****@headfirst.co.uk
www.headfirst.co.uk www.callofcthulhu.com
-
"Jonathan" <jo***@earthling.net> wrote in message
news:66*************************@posting.google.co m...
I am trying to add an item to a checked list box, like:

clbList.Items.add("Hello",true)

I get an error back:

Run-time exception thrown: System.ArgumentOutOfRangeException - Specified
argument was out of the range of valid values. Parameter name: '-1' is
not a
valid value for index.


true is a boolean but its integer representation is -1.
It maybe that this suggests that the 2nd parameter was expecting an
integer?

Jonathan

Nov 20 '05 #21

P: n/a
Hi, Simon

I think it really depends on whether your first priority is getting it
working or figuring out what happened. In the former case I would recreate
the for in a new project, pasting your code ONLY from the old to the new.
If that works, dive into the form designer code and look for differences.

If you have to know what happened, try pealing the onion. Chop away what
should be irrelevant code and controls is small chunks until things start
working. Put the last piece back and see if it fails. Then go over the 2
files with a fine tooth comb. Something should be obvious.

Hope this helps,

John Eikanger
Microsoft Developer Support

This posting is provided “AS IS” with no warranties, and confers no rights.
--------------------
| From: "Simon Jefferies" <si****@headfirst.co.uk>
| Subject: Re: Adding an item to a Checked List Box
| X-Tomcat-NG: microsoft.public.dotnet.languages.vb
|
| Thanks for your reply,
|
| When I created a new project it worked! Mmmm...
|
| I haven't touched the Windows Form designer generated code section.
|
| Any ideas on what to try next?
|
| Regards
| Simon Jefferies
| Tools Programmer, Headfirst Productions
| mailto:si****@headfirst.co.uk
| www.headfirst.co.uk www.callofcthulhu.com
| -
| "John Eikanger [MSFT]" <jo****@online.microsoft.com> wrote in message
| news:J6**************@cpmsftngxa06.phx.gbl...
| > Hi, Simon
| >
| > I can't get it to repro here either.
| >
| > What happens when you start a new project, add a checked list box & a
| > button, and put your code in the button's click event? If that works,
| > there is probably something wrong in your form or project files. Have
you
| > edited the code in the Windows Form Designer generated code section?
That
| > could be the culpret. If the simple project fails, please zip up the
| > simple project and attach it to a post. That will give us something
real
| > to play with.
| >
| > Hope this helps,
| >
| > John Eikanger
| > Microsoft Developer Support
| >
| > This posting is provided "AS IS" with no warranties, and confers no
| > rights.
| > --------------------
| > | From: "Simon Jefferies" <si****@headfirst.co.uk>
| > | Subject: Re: Adding an item to a Checked List Box
| > | Date: Thu, 15 Apr 2004 15:57:44 +0100
| > | X-Tomcat-NG: microsoft.public.dotnet.languages.vb
| > |
| > | I don't get an exception when I comment out the BeginUpdate, Clear and
| > | EndUpdate.
| > |
| > | I put back in the Clear() and its still working, so it means
| > BeginUpdate()
| > | or EndUpdate() or both causes this problem?
| > |
| > | Yes, I am performing this in the main application thread.
| > |
| > | Why would this happen?
| > |
| > | --
| > | Regards
| > | Simon Jefferies
| > | Tools Programmer, Headfirst Productions
| > | mailto:si****@headfirst.co.uk
| > | www.headfirst.co.uk www.callofcthulhu.com
| > | -
| > | "Herfried K. Wagner [MVP]" <hi***************@gmx.at> wrote in message
| > | news:O1**************@TK2MSFTNGP10.phx.gbl...
| > | > Simon,
| > | >
| > | > * "Simon Jefferies" <si****@headfirst.co.uk> scripsit:
| > | >> clbWaves.BeginUpdate()
| > | >> clbWaves.Items.Clear()
| > | >> Try
| > | >> clbWaves.Items.Add("Hello", True)
| > | >> Catch ex As Exception
| > | >> End Try
| > | >>
| > | >> clbWaves.EndUpdate()
| > | >>
| > | >> The Catch statement is called with the Out of range exception.
| > | >
| > | > Does the exception occur if you skip the 'Clear', 'BeginUpdate', and
| > | > 'EndUpdate'? Are you sure you are performing the operation in the
| > main
| > | > GUI thread?
| > | >
| > | > --
| > | > Herfried K. Wagner [MVP]
| > | > <URL:http://dotnet.mvps.org/>
| > |
| > |
| > |
| >
|
|
|

Nov 20 '05 #22

P: n/a
* "Simon Jefferies" <si****@headfirst.co.uk> scripsit:
I've just double-checked the 2nd parameter and it is "IsChecked" and it
requires a boolean.


That's what MSDN says too.

--
Herfried K. Wagner [MVP]
<URL:http://dotnet.mvps.org/>
Nov 20 '05 #23

P: n/a
* "Simon Jefferies" <si****@headfirst.co.uk> scripsit:
I've put the code behind a command button to perform the following:

clbWaves.BeginUpdate()
clbWaves.Items.Clear()
clbWaves.Items.Add("Hello", True)
clbWaves.EndUpdate()

and it still comes up with the exception...


I have tested it on my VS.NET 2003 machine -- not able to repro the
problem...

--
Herfried K. Wagner [MVP]
<URL:http://dotnet.mvps.org/>
Nov 20 '05 #24

P: n/a
Hi, Simon

The problem seems to be setting the Sorted property to True. The following
works for me:

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button1.Click

clbWaves.BeginUpdate()
clbWaves.Sorted = False
clbWaves.Items.Clear()
clbWaves.Items.Add("Hello", True)
clbWaves.Sorted = True
clbWaves.EndUpdate()
End Sub

As to >why< Sorted causes problems, that will take some research. I will
let you know what I find out.

Thank you for choosing the MSDN Managed Newsgroups,

John Eikanger
Microsoft Developer Support

This posting is provided “AS IS” with no warranties, and confers no rights.
--------------------
| From: "Simon Jefferies" <si****@headfirst.co.uk>
| Subject: Re: Adding an item to a Checked List Box
| Date: Mon, 19 Apr 2004 10:03:43 +0100
| X-Tomcat-NG: microsoft.public.dotnet.languages.vb
|
| Thanks for your help,
|
| I've created a new form, and copied the problem code across. I've
stripped
| out all my events etc leaving just a simple button click event to add
items
| to the checked list box. It still doesn't work. I've compared a working
form
| with the unworking one and cant see anything that would cause this
problem.
|
| I've attached the project - two forms inside, Form1 (not working) and
| WorkingForm.
|
| Please let me know if you find anything thats wrong with this form.
|
| Regards
| Simon Jefferies
| Tools Programmer, Headfirst Productions
| mailto:si****@headfirst.co.uk
| www.headfirst.co.uk www.callofcthulhu.com
| -
| "John Eikanger [MSFT]" <jo****@online.microsoft.com> wrote in message
| news:e9**************@cpmsftngxa06.phx.gbl...
| > Hi, Simon
| >
| > I think it really depends on whether your first priority is getting it
| > working or figuring out what happened. In the former case I would
| > recreate
| > the for in a new project, pasting your code ONLY from the old to the
new.
| > If that works, dive into the form designer code and look for
differences.
| >
| > If you have to know what happened, try pealing the onion. Chop away
what
| > should be irrelevant code and controls is small chunks until things
start
| > working. Put the last piece back and see if it fails. Then go over
the 2
| > files with a fine tooth comb. Something should be obvious.
| >
| > Hope this helps,
| >
| > John Eikanger
| > Microsoft Developer Support
| >
| > This posting is provided "AS IS" with no warranties, and confers no
| > rights.
| > --------------------
| > | From: "Simon Jefferies" <si****@headfirst.co.uk>
| > | Subject: Re: Adding an item to a Checked List Box
| > | X-Tomcat-NG: microsoft.public.dotnet.languages.vb
| > |
| > | Thanks for your reply,
| > |
| > | When I created a new project it worked! Mmmm...
| > |
| > | I haven't touched the Windows Form designer generated code section.
| > |
| > | Any ideas on what to try next?
| > |
| > | Regards
| > | Simon Jefferies
| > | Tools Programmer, Headfirst Productions
| > | mailto:si****@headfirst.co.uk
| > | www.headfirst.co.uk www.callofcthulhu.com
| > | -
| > | "John Eikanger [MSFT]" <jo****@online.microsoft.com> wrote in message
| > | news:J6**************@cpmsftngxa06.phx.gbl...
| > | > Hi, Simon
| > | >
| > | > I can't get it to repro here either.
| > | >
| > | > What happens when you start a new project, add a checked list box &
a
| > | > button, and put your code in the button's click event? If that
works,
| > | > there is probably something wrong in your form or project files.
Have
| > you
| > | > edited the code in the Windows Form Designer generated code section?
| > That
| > | > could be the culpret. If the simple project fails, please zip up
the
| > | > simple project and attach it to a post. That will give us something
| > real
| > | > to play with.
| > | >
| > | > Hope this helps,
| > | >
| > | > John Eikanger
| > | > Microsoft Developer Support
| > | >
| > | > This posting is provided "AS IS" with no warranties, and confers no
| > | > rights.
| > | > --------------------
| > | > | From: "Simon Jefferies" <si****@headfirst.co.uk>
| > | > | Subject: Re: Adding an item to a Checked List Box
| > | > | Date: Thu, 15 Apr 2004 15:57:44 +0100
| > | > | X-Tomcat-NG: microsoft.public.dotnet.languages.vb
| > | > |
| > | > | I don't get an exception when I comment out the BeginUpdate,
Clear
| > and
| > | > | EndUpdate.
| > | > |
| > | > | I put back in the Clear() and its still working, so it means
| > | > BeginUpdate()
| > | > | or EndUpdate() or both causes this problem?
| > | > |
| > | > | Yes, I am performing this in the main application thread.
| > | > |
| > | > | Why would this happen?
| > | > |
| > | > | --
| > | > | Regards
| > | > | Simon Jefferies
| > | > | Tools Programmer, Headfirst Productions
| > | > | mailto:si****@headfirst.co.uk
| > | > | www.headfirst.co.uk www.callofcthulhu.com
| > | > | -
| > | > | "Herfried K. Wagner [MVP]" <hi***************@gmx.at> wrote in
| > message
| > | > | news:O1**************@TK2MSFTNGP10.phx.gbl...
| > | > | > Simon,
| > | > | >
| > | > | > * "Simon Jefferies" <si****@headfirst.co.uk> scripsit:
| > | > | >> clbWaves.BeginUpdate()
| > | > | >> clbWaves.Items.Clear()
| > | > | >> Try
| > | > | >> clbWaves.Items.Add("Hello", True)
| > | > | >> Catch ex As Exception
| > | > | >> End Try
| > | > | >>
| > | > | >> clbWaves.EndUpdate()
| > | > | >>
| > | > | >> The Catch statement is called with the Out of range exception.
| > | > | >
| > | > | > Does the exception occur if you skip the 'Clear',
'BeginUpdate',
| > and
| > | > | > 'EndUpdate'? Are you sure you are performing the operation in
the
| > | > main
| > | > | > GUI thread?
| > | > | >
| > | > | > --
| > | > | > Herfried K. Wagner [MVP]
| > | > | > <URL:http://dotnet.mvps.org/>
| > | > |
| > | > |
| > | > |
| > | >
| > |
| > |
| > |
| >
|
|
|

Nov 20 '05 #25

P: n/a
Found it. Known bug that we found too late to get into 7.1

The problem is that you call BeginUpdate, so all additions have to wait
until after the EndUpdate. The problem is that the we try to set the
checked state immediately and the there is nothing there yet to send. It
isn't clear why Sorted makes a difference

Please try the work around that I provided and let me know if it works for
you.

John Eikanger
Microsoft Developer Support

This posting is provided “AS IS” with no warranties, and confers no rights.

Nov 20 '05 #26

P: n/a
Many thanks for replying and finding out what the problem was.

I have tried the workaround and it works! :-)

Best Wishes
Simon Jefferies
Tools Programmer, Headfirst Productions
mailto:si****@headfirst.co.uk
www.headfirst.co.uk www.callofcthulhu.com
-
"John Eikanger [MSFT]" <jo****@online.microsoft.com> wrote in message
news:9$**************@cpmsftngxa10.phx.gbl...
Found it. Known bug that we found too late to get into 7.1

The problem is that you call BeginUpdate, so all additions have to wait
until after the EndUpdate. The problem is that the we try to set the
checked state immediately and the there is nothing there yet to send. It
isn't clear why Sorted makes a difference

Please try the work around that I provided and let me know if it works for
you.

John Eikanger
Microsoft Developer Support

This posting is provided "AS IS" with no warranties, and confers no
rights.

Nov 20 '05 #27

This discussion thread is closed

Replies have been disabled for this discussion.