I have a case statement that evaluates a string in a combo box on a form which is either English or Metric. What I'm finding is that the case statement does not see the pull down box contents which is loaded by default unless it is physically reselected by the user. In other words the combo box defaults to "metric" but the case statement does not recognize it unless I go and reselect "metric" in the combo box. Any help would be appreciated.

Recommended Answers

All 13 Replies

Whats wrong with the other question you already have a thread on this subject for?

different problem

i don't understand very well your problem. Give us the code, example... don't let us guess.

If this is the problem I think it is, I usually fix it by using the Text property of the combo box. It should allow you to get the text of what's in the combo box without the user actually having to select it.

that is what im using the text property of the combo box

OK...have you tried using the SelectedItem property?

OK...have you tried using the SelectedItem property?

Yes I get an error saying " a value of an integral type is expected"

Show some code, show the line with the error, show what you tried to do to fix it

Here is my code and when I run it always gets to the default althought there are strings showing in the combo box that came from the data base

switch (bunitsCB.Text)
{
case "Metric":
bl = Convert.ToDecimal(blanklTB.Text) / Convert.ToDecimal(25.4);
bw = Convert.ToDecimal(blankwTB.Text) / Convert.ToDecimal(25.4);
bp = Convert.ToDecimal(blankpTB.Text) / Convert.ToDecimal(25.4);
pd = Convert.ToDecimal(partdepthTB.Text) / Convert.ToDecimal(25.4);break;
case "English":
bl = Convert.ToDecimal(blanklTB.Text);
bw = Convert.ToDecimal(blankwTB.Text);
bp = Convert.ToDecimal(blankpTB.Text);
pd = Convert.ToDecimal(partdepthTB.Text);break;
default:
bl = 0;
bw = 0;
bp = 0;
pd = 0;
checkLB.Items.Add("YOU MUST SELECT A BLANK UNIT OF MEASURE");break;
}
switch (dieunitsCB.Text)
{
case "Metric":
dl = Convert.ToDecimal(dielTB.Text) / Convert.ToDecimal(25.4);
dw = Convert.ToDecimal(diewTB.Text) / Convert.ToDecimal(25.4);
ds = Convert.ToDecimal(dieshTB.Text) / Convert.ToDecimal(25.4);break;
case "English":
dl = Convert.ToDecimal(dielTB.Text);
dw = Convert.ToDecimal(diewTB.Text);
ds = Convert.ToDecimal(dieshTB.Text);break;
default:
dl = 0;
dw = 0;
ds = 0;
checkLB.Items.Add("YOU MUST SELECT A DIE UNIT OF MEASURE");break;
}

And in debugging what was the value of say "bunitsCB.Text"

And in debugging what was the value of say "bunitsCB.Text"

Thats just the problem. Im not getting a value for bunitsCB.Text. The value is visible on the screen but I cannot figure out how to call it for the switch statement. It is in the database, it shows in the combo box but unless I reselect it it does not get assigned to bunitsCB.Text.

HELPPPPPPP

Then dont use the .Text but the selected item... and yes I know you had an error before but it was the right thing just in the wrong way

When you set the DataSource or load the Items manually, you could just set the SelectedIndex property to 0. That should keep you from getting errors about nothing being selected. I guess whether or not you can do this would have to depend on any Business rules in place or requirements.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.