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

C# Winform Application Case Switch Problem

Hi, I have some code, below, that takes input from a combobox and is supposed to parse it and display it. However, it doesn't work. I can't figure out why.

The combobox is the one for the resolution code, which specifies how the ticket was closed.

The code compiles fine, but the box persists with the number instead of the actual code. Thoughts?

if (comboBox12.Text != "")
{
int ResCode = Convert.ToInt32(comboBox12.Text);
string Resolution = "";
switch (ResCode)
{
case 0:
Resolution = "Initial Contact";
break;
case 1:
Resolution = "Remote";
break;
case 2:
Resolution = "On-Site";
break;
case 3:
Resolution = "User Resolved";
break;
case 4:
Resolution = "Cancelled";
break;
case 5:
Resolution = "Code";
break;
case 6:
Resolution = "Duplicate";
break;
}
comboBox12.Text = Resolution;
}
else
{
comboBox12.Text = "";
}
Apr 4 '08 #1
7 3130
rjvrnjn
26
Can you post a sample of what is contained in the combo box? Like, the user sees "Resolution Name" and the value property stores 3.
Apr 4 '08 #2
Hi, I have some code, below, that takes input from a combobox and is supposed to parse it and display it. However, it doesn't work. I can't figure out why.

The combobox is the one for the resolution code, which specifies how the ticket was closed.

The code compiles fine, but the box persists with the number instead of the actual code. Thoughts?

if (comboBox12.Text != "")
{
int ResCode = Convert.ToInt32(comboBox12.Text);
string Resolution = "";
switch (ResCode)
{
case 0:
Resolution = "Initial Contact";
break;
case 1:
Resolution = "Remote";
break;
case 2:
Resolution = "On-Site";
break;
case 3:
Resolution = "User Resolved";
break;
case 4:
Resolution = "Cancelled";
break;
case 5:
Resolution = "Code";
break;
case 6:
Resolution = "Duplicate";
break;
}
comboBox12.Text = Resolution;
}
else
{
comboBox12.Text = "";
}
i assume you want the value of the item selected on the combobox...
for that use :

Expand|Select|Wrap|Line Numbers
  1. this.comboBox1.SelectedValue
if what you really want is the text, then you should debug the app see if the text contains some unwanted character or spaces in it.
Apr 4 '08 #3
i assume you want the value of the item selected on the combobox...
for that use :

Expand|Select|Wrap|Line Numbers
  1. this.comboBox1.SelectedValue
if what you really want is the text, then you should debug the app see if the text contains some unwanted character or spaces in it.
Making headway using this solution. Changed my code to:

this.comboBox12.SelectedValue = Resolution;

gives me the error:

"The input string is not in the correct format."

The Database value it's pulling is an INT, but I want to put a string in the box. Is this possible?
Apr 4 '08 #4
rjvrnjn
26
That was the reason I asked you if you can provide us with what are you attaching as datasource to the combo box. If you can answer the below questions you'll be helped in the correct direction (it appears from the posts above).
a.) How are you setting the datasource? Is it a datatable or a list of items?
b.) What has been set as Text field and what has been set as Value field?

Also, in the post above it was suggested that you put the code in the CASE statement expression and not to assign it. Something like:
Switch this.comboBox12.SelectedValue
Case 0
Case 1... yada...yada...yada..

Try that.
Apr 5 '08 #5
That was the reason I asked you if you can provide us with what are you attaching as datasource to the combo box. If you can answer the below questions you'll be helped in the correct direction (it appears from the posts above).
a.) How are you setting the datasource? Is it a datatable or a list of items?
b.) What has been set as Text field and what has been set as Value field?

Also, in the post above it was suggested that you put the code in the CASE statement expression and not to assign it. Something like:
Switch this.comboBox12.SelectedValue
Case 0
Case 1... yada...yada...yada..

Try that.

The combobox datasource is a datatable, it's the field for the resolution code for that ticket. The textfield has been set to to the value in the datatable for that ticket, like 1, 2, 3, etc. The value field is blank. That's why I figured I could do combobox55.text etc...

I don't quite understand your case statement example. Could you elaborate?
Apr 6 '08 #6
rjvrnjn
26
I don't quite understand your case statement example. Could you elaborate?
Well in case the only thing bound in your combo box is text field then you should try either
Combobox.SelectedText
OR
Combobox.SelectedItem.Text

do the cast to Int as in your previous post. I guess it should work fine.
Apr 7 '08 #7
rjvrnjn
26
Oh, I just realised that I'd been hearing what I thought you're saying rather than what you're saying!! Sorry for that.
Ok, I'll try to explain the problem that you're facing and let's see if that makes sense. You've assigned a datatable as datasource to the combo box and then set the Displaymember as one of the columns of the datatable. Now using the case statement you're trying to change the display text of the combo box which will not happen as the text is not part of the datasource. In fact, the compiler should have thrown a run time exception but I guess they handle it internally (not sure of the hows involved).

It'll make more sense if in one of the cases (say for code 2) you do something like
combobox1.text = "3";
This will change the code that is visible in the combo box as "3" is part of the datasource. Hope this makes sense.
Apr 7 '08 #8

Sign in to post your reply or Sign up for a free account.

Similar topics

3
by: Matthias Heuer | last post by:
Hi, we try to deploy a quite heavyweight .NET (C#) Rich Client App (2 Tier) via IIS Server Zero Touch, but it requires about 4-6 times more Processor Time and is thus 3-4 times slower than if...
0
by: Cenray | last post by:
How to generate a web request from a Winform Application using a WebService? In a C# Windows Application, when I try to genrate a web request using the following code, it is woking fine ...
3
by: Mrinal Kamboj | last post by:
Hi , I am doing some experimentation , so i created a winform exe , that on load event creates a NotifyIcon object for System Tray Icon . Now if i run that application normally by VS.net or...
6
by: William F. Kinsley | last post by:
I am thinking of porting an existing MFC application to MC++ and I have created a simple MFC application to test the environment. My sample MFC application is compilied with the /clr switch. I...
6
by: QuenHo | last post by:
Hi All, I've build a winform application with vb.net which accepts command-line parameters. If I tell windows to open certain files with this application all works fine, but windows does NOT...
14
by: Monty | last post by:
Hello, I have created a solution which has both a web UI and a winform UI, the latter is just for administrators. The Web UI (a Web Application Project) and the winform project both...
1
by: JDeats | last post by:
If you create a new C# Windows Application project in Visual Studio.NET 2003 or 2005 and proceed to. 1. Make default form size 800x600 2. Drop a CheckBoxList control and dock it to the left 3....
9
by: somacore | last post by:
I have a winform with a combobox. This combobox's text is set to a value from the database (in this case, a number). In my code I take the number and convert it to the proper text, returning the...
9
by: Victory | last post by:
Hi, Our group has to develop a new UI. We are using a third party and have them develop this since we don't have a lot of experience in doing this. We want it to be accessible through the web...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

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.