Specified cast is not valid

  • Thread starter Thread starter Guest
  • Start date Start date
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)
 
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]
 
* "=?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.
 
Back
Top