473,396 Members | 2,061 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

Adding an item to a Checked List Box

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
26 2788
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
"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
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
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
"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
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
"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
* "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
* "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
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
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
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
* "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
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
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
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
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
"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
> 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
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
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
* "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
* "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
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
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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: Claire | last post by:
When I run the following code through on the first round, my sub-menu (branched off mnuOpenPorts menuitem) shows a nice list of ports. When it gets run through on the 2nd pass, the sub menu...
4
by: Claire | last post by:
Sorry Ive added this twice (sortof) but if I'd added an addendum to the first one then this would probably have been ignored. This problem affects a ContextMenu attached to a NotifyIcon object. I...
3
by: Jim Heavey | last post by:
Trying to figure out the technique which should be used to add rows to a datagrid. I am thinking that I would want an "Add" button on the footer, but I am not quite sure how to do that. Is that...
1
by: sianan | last post by:
I tried to use the following example, to add a checkbox column to a DataGrid in an ASP.NET application: http://www.codeproject.com/aspnet/datagridcheckbox.asp For some reason, I simply CAN'T get...
3
by: Dean Slindee | last post by:
In a checked listbox, I am allowing drag/drop of the items within (resequencing). Problem is, when dropping a checked item, the checked state always reverts to unchecked (unwanted). Anyone know...
4
by: Kevin | last post by:
Hello. My app uses user-based menu generation where all of the menu items are loaded from a SQLServer 2k database when the user logs in to the app. All is well except I cannot get an Access Key to...
1
by: Ulrich Wisser | last post by:
Hi, what does that line from my logfile mean? Adding missing FROM-clause entry for table "customer" Would pg change my SQL queries on the fly? TIA
1
by: The Eclectic Electric | last post by:
I'd be very grateful if anyone could help me with this. From my limited knowledge of Javascript I don't think it is possible, but I'll punt anyway. I downloaded and very slightly adapted this...
2
by: Steve | last post by:
I am working on a program that works like a check in/check out system. There is a folder on a network drive that stores a bunch of vb programs. This program will check in and check out programs...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.