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
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
I would say try more like this if you need to. -
number = int.Parse(comboBox.Items[comboBox.SelectedIndex].ToString());
-
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
lol...sorry my earlier post got repeated...
cheers,
hhak
Sign in to post your reply or Sign up for a free account.
Similar topics
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...
|
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...
|
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...
|
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...
|
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...
|
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...
|
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....
|
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...
|
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.
*
...
|
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...
|
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
|
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...
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
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...
|
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...
|
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,...
|
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...
|
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...
| |