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

C# problem: trying to assign a combobox selected value to an integer variable

3
Hi all,
Im pretty new to C#, im trying to assign a combobox selected value to a int variable.

int number;

combobox has items added (1,2,3,4,...9)

when i select a number from the combobox i want to assign this number to my integer variable.

thanks in advance.

cheers,
hhak

added:
at the moment i can do it by

if (comboBox.Items[comboBox.SelectedIndex].ToString() == "1")
{
number = 1;
}
else if (comboBox.Items[comboBox.SelectedIndex].ToString() == "2")
{
number = 2;
}
....but this is a little long
Oct 15 '07 #1
4 27871
HI,
you can simply assign the value directly to the variable:

number = (int)comboBox.Items[comboBox.SelectedIndex].ToString()







Hi all,
Im pretty new to C#, im trying to assign a combobox selected value to a int variable.

int number;

combobox has items added (1,2,3,4,...9)

when i select a number from the combobox i want to assign this number to my integer variable.

thanks in advance.

cheers,
hhak

added:
at the moment i can do it by

if (comboBox.Items[comboBox.SelectedIndex].ToString() == "1")
{
number = 1;
}
else if (comboBox.Items[comboBox.SelectedIndex].ToString() == "2")
{
number = 2;
}
....but this is a little long
Oct 15 '07 #2
Plater
7,872 Expert 4TB
I would say try more like this if you need to.
Expand|Select|Wrap|Line Numbers
  1. number = int.Parse(comboBox.Items[comboBox.SelectedIndex].ToString()); 
  2.  
Oct 15 '07 #3
hhak
3
Thanks alot guys,

this worked for me

"number = int.Parse(comboBox.Items[comboBox.SelectedIndex].ToString());"

lol, my 20 lines is now 1

thanks again...

cheers,
hhak
Oct 16 '07 #4
hhak
3
lol...sorry my earlier post got repeated...

cheers,
hhak
Oct 16 '07 #5

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

Similar topics

8
by: rdlebreton | last post by:
Hi, Folks! I've been trying to develop my own version of these draggable layers and I have been limiting myself to IE6...for now. I have looked at some other examples to get ideas of creating...
6
by: Ron L | last post by:
I have a dataset whose source is a SQL 2k stored procedure that I am trying to display in a datagrid. This datasource has 4 columns that I am interested in here, a text column and 3 value columns...
5
by: Eric A. Johnson | last post by:
Hi Everyone, I am at my wit's end here. I have a combobox (combyQueryTitle) that I need to use in order to select a query for my database project. Therefore, I am using the...
4
by: sonu | last post by:
Hi, I have a problem regarding use of a ListviewSorter class which is used to sort the items in the listview. Basically I have a listview with three columns as "Name","Size" and...
2
by: Rayne | last post by:
I have a combobox that is bound to a datasource. It lists the users in the system and I want it to automatically select the current logged on user, so that the screen loads that user's information...
0
by: mjsterz | last post by:
I've been working with VB .NET for less than a year and this is the first time I've posted on one of these groups, so let me apologize beforehand if I'm being unclear, not posting my issue...
1
by: Thelma Roslyn Lubkin | last post by:
I have a form with several comboboxes whose contents I'm trying to initialize from a table. The table, ComboSelections, has 3 fields, an autonumber ID and two text fields, ListCode and ListEntry....
2
by: sirdavethebrave | last post by:
Hi guys - I have written a form, and a stored procedure to update the said form. It really is as simple as that. A user can go into the form, update some fields and hit the update button to...
1
by: Man4ish | last post by:
Hi, How Eventlistner can be used with rendred combo box. I got one example of combobox in table as follows . /* * Copyright (c) 1995 - 2008 Sun Microsystems, Inc. All rights reserved. * ...
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
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
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: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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:
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
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
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.