问题描述
我希望当用户从comobox中选择项目时,文本框会显示值:例如:4,5
示例;
当用户从comobox中选择A +时
textbox1自动显示4。
我想为很多comobox做这个,请帮助我:(
我尝试了什么:
i尝试过就好了;
浮动a =(浮动)Convert.ToDouble(textBox1。文字);
if(comboBox1.Text ==A +)
{
textBox1.Text =4;
}
但不工作
I want that when user select item from comobox the textbox show the value: e.g:4, 5
EXAMPLE;
when user select "A+" from comobox the textbox1 show "4" automatically.
And i want to do this for many comobox so,please help me :(
What I have tried:
i have tried just like;
float a = (float)Convert.ToDouble(textBox1.Text);
if (comboBox1.Text == "A+")
{
textBox1.Text = "4";
}
but not working
推荐答案
private void Form3_Load(object sender, EventArgs e)
{
DataTable dt = new DataTable();
dt.Columns.Add("Value");
dt.Columns.Add("Text");
dt.Rows.Add("", "");
dt.Rows.Add("1", "A");
dt.Rows.Add("2", "B");
dt.Rows.Add("3", "C");
dt.Rows.Add("4", "A+");
comboBox1.DisplayMember = "Text";
comboBox1.ValueMember = "Text";
comboBox1.DataSource = dt;
}
private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)
{
textBox1.Text = (comboBox1.SelectedItem as DataRowView)[0].ToString();
}
选择A +时,4将分配给文本框。
When you select A+ , 4 will assigned to Textbox.
这篇关于当从comobox中选择itom时,如何在文本框中传递值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!