Windows Develop Bookmark and Share   
 index > Windows Forms Sample Applications > Please help! Need help for passing variable from a combobox
 

Please help! Need help for passing variable from a combobox

Hi everyone,

Does anyone know how to pass a "string" from a combobox to a textbox? While I want to convert the string (say, am or pm), and convert them to a number?

Please help

Many thanks!

akhui1  Monday, February 18, 2008 9:50 AM

Try this,

Passing string from comBox to textBox

Code Snippet

textBox1.Text = comboBox1.SelectedItem.ToString();

If you want to convert String to Number, try to convert them in safe way:

Code Snippet

int Num;

if (int.TryParse(comboBox1.SelectedItem.ToString(), out Num))

{

textBox1.Text = Num;

}

else

{

MessageBox.Show("Sorry! String wasn't Convertable.");

}

Hope this helps.
Mind Sport  Monday, February 18, 2008 7:14 PM

Try this,

Passing string from comBox to textBox

Code Snippet

textBox1.Text = comboBox1.SelectedItem.ToString();

If you want to convert String to Number, try to convert them in safe way:

Code Snippet

int Num;

if (int.TryParse(comboBox1.SelectedItem.ToString(), out Num))

{

textBox1.Text = Num;

}

else

{

MessageBox.Show("Sorry! String wasn't Convertable.");

}

Hope this helps.
Mind Sport  Monday, February 18, 2008 7:14 PM

You can use google to search for other answers

Custom Search

More Threads

• how to create those dataset class files in web services?
• Blogs?
• Install webservices on remote network server
• Authentication Error
• Does teleporting deserialize creature state correct?
• reg windows appliation deployment..
• Inclusion of "content" files in build... HOWTO?
• Well, this is it
• Online/Offline Quirk
• naka invasion