Adding an item to a Checked List Box

J

John Eikanger [MSFT]

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" <[email protected]>
| 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:[email protected]
| www.headfirst.co.uk www.callofcthulhu.com
| -
| | > 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" <[email protected]>
| > | 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:[email protected]
| > | www.headfirst.co.uk www.callofcthulhu.com
| > | -
| > | | > | > Simon,
| > | >
| > | > * "Simon Jefferies" <[email protected]> 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/>
| > |
| > |
| > |
| >
|
|
|
 
H

Herfried K. Wagner [MVP]

* "Simon Jefferies said:
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...
 
H

Herfried K. Wagner [MVP]

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

That's what MSDN says too.
 
J

John Eikanger [MSFT]

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" <[email protected]>
| 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:[email protected]
| www.headfirst.co.uk www.callofcthulhu.com
| -
| | > 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" <[email protected]>
| > | 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:[email protected]
| > | www.headfirst.co.uk www.callofcthulhu.com
| > | -
| > | | > | > 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" <[email protected]>
| > | > | 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:[email protected]
| > | > | www.headfirst.co.uk www.callofcthulhu.com
| > | > | -
| > message
| > | > | | > | > | > Simon,
| > | > | >
| > | > | > * "Simon Jefferies" <[email protected]> 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/>
| > | > |
| > | > |
| > | > |
| > | >
| > |
| > |
| > |
| >
|
|
|
 
J

John Eikanger [MSFT]

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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top