473,320 Members | 1,820 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,320 software developers and data experts.

Combo box "specified cast is not valid" error

Not sure why all of a sudden this line of code:

cmbProductCategoryTreeDisplayName.SelectedIndex = 0;

is producing a "Specified cast is not valid error". In the watch it has 1
item in it at index 0. This code hasn't been changed in months and it has
never had this problem before...

Thanks for any help you guys can give me!

-Jayyde
Jun 29 '06 #1
3 3180
Hmmm, very strange!

Sure it's a zero and not an Oh?
The Combo is definatly instantiated at that point?
Definatly has at least one item in it.
Don't think you'd get that error even if it wasn't
Otherwise, can't see anything wrong.
Try this code as an experiment:

int indexValue = 0;
if(cmbProductCategoryTreeDisplayName.Items.Count > 0)
cmbProductCategoryTreeDisplayName.SelectedIndex = indexValue;
else
MessageBox.Show("Wait a minute... there's nothing here to set!!");

Cheers,

Chris.
"Jayyde" <an**@hotmail.com> wrote in message
news:e5**************@TK2MSFTNGP03.phx.gbl...
Not sure why all of a sudden this line of code:

cmbProductCategoryTreeDisplayName.SelectedIndex = 0;

is producing a "Specified cast is not valid error". In the watch it has 1
item in it at index 0. This code hasn't been changed in months and it has
never had this problem before...

Thanks for any help you guys can give me!

-Jayyde

Jun 29 '06 #2
One other thing...

Is it possible that the error is in fact coming from somewhere else, that is
being triggered by that assignment? (say the SelectedIndexChanged event)?
"ChrisM" <ch**************@suedeyahoo.com> wrote in message
news:eg**************@TK2MSFTNGP04.phx.gbl...
Hmmm, very strange!

Sure it's a zero and not an Oh?
The Combo is definatly instantiated at that point?
Definatly has at least one item in it.
Don't think you'd get that error even if it wasn't
Otherwise, can't see anything wrong.
Try this code as an experiment:

int indexValue = 0;
if(cmbProductCategoryTreeDisplayName.Items.Count > 0)
cmbProductCategoryTreeDisplayName.SelectedIndex = indexValue;
else
MessageBox.Show("Wait a minute... there's nothing here to set!!");

Cheers,

Chris.
"Jayyde" <an**@hotmail.com> wrote in message
news:e5**************@TK2MSFTNGP03.phx.gbl...
Not sure why all of a sudden this line of code:

cmbProductCategoryTreeDisplayName.SelectedIndex = 0;

is producing a "Specified cast is not valid error". In the watch it has
1 item in it at index 0. This code hasn't been changed in months and it
has never had this problem before...

Thanks for any help you guys can give me!

-Jayyde


Jun 29 '06 #3
Jayyde wrote:
Not sure why all of a sudden this line of code:

cmbProductCategoryTreeDisplayName.SelectedIndex = 0;

is producing a "Specified cast is not valid error". In the watch it has 1
item in it at index 0. This code hasn't been changed in months and it has
never had this problem before...

Thanks for any help you guys can give me!

-Jayyde


Hi Jayyde,

Check your stack trace for the exception, and see where it's coming from.
If you are adding objects straight into the Items collection, i.e. not just
strings/etc then perhaps one of those objects are playing up.

--
Hope this helps,
Tom Spink
Jun 29 '06 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: Özden Irmak | last post by:
Hello, In my application, I've to cast DocumentDesigner class to my own derived class,MyDocumentDesigner, in order to reach the protected properties in DocumentDesigner class. But everytime I...
0
by: Peter Afonin | last post by:
Hello: When I try to access a SQL server or a network share from an ASP.Net application that I run on my computer, I run into security problems (for instance, I cannot execute DTS package using...
8
by: Charles | last post by:
I do not understand why I am getting a "Specified cast is not valid" error, since it has worked before. Something has changed and I am not really sure what it could be. I am looking for something...
4
by: Mike Cooper | last post by:
There is something about inherited classes I evidently don't know... I wrote the following class: Class Class1 inherits System.Windows.Forms.DataGridTextBoxColumn End Class There is...
10
by: roy.anderson | last post by:
Error is thus: "Cast from type 'DBNull' to type 'String' is not valid." Simple, right? Well, no (or at least not for me). Here's a function, followed by the calling code below: Function...
3
by: keithb | last post by:
Using a GridView, I get a "Specified cast is not valid" error when binding the Visible propery of a hyperlink control to a DataTable text field. The error goes away if I replace the data binding...
12
by: Pao | last post by:
Hi all For all NEW sites (virtual directories) that I create, I receive always the same error: (I translate so may be a little different) Impossible to visualize the XML page Impossible to...
0
by: Curious | last post by:
Hi, I'm not sure if this is the right place to post such command issues. If you know a better forum where people respond to messages fairly often, please let me know! Anyway, would appreciate...
3
by: =?Utf-8?B?UGF1bCBQcmV3ZXR0?= | last post by:
I'm attempting to use LINQ to insert a record into a child table and I'm receiving a "Specified cast is not valid" error that has something to do w/ the keys involved. The stack trace is: ...
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
0
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you

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.