Specified cast is not valid

G

Guest

I have a CheckedListBox control on a form. Whenever I want to check the item in the CheckedListBox with the following code, it give me an error message 'Specified cast is not valid'. why

chklstType.Items.Add("abc", True)
 
M

Morten Wennevik

Hi Chrysan,

As Jakob says, there is nothing wrong with your line. CheckedListBox.Items.Add uses objects, so it will accept anything you try to put into it.

The error message indicate that you have used a cast somewhere, and that this cast is not valid for that particular object.



Happy coding!
Morten Wennevik [C# MVP]
 
H

Herfried K. Wagner [MVP]

* "=?Utf-8?B?Q2hyeXNhbg==?= said:
I have a CheckedListBox control on a form. Whenever I want to check
the item in the CheckedListBox with the following code, it give me an
error message 'Specified cast is not valid'. why?

chklstType.Items.Add("abc", True)

Your code should work.
 

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