Click here to Skip to main content
15,885,546 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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
Posted
Updated 30-Jul-16 0:56am
Comments
Richard MacCutchan 30-Jul-16 6:38am    
You would be better using a pre-poulated ListBox. You can then just get the currently selected item when the user makes a selection.

1 solution

try like this

C#
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();
      }


When you select A+ , 4 will assigned to Textbox.
 
Share this answer
 
Comments
Member 12632487 8-Aug-16 5:12am    
Yes it is the better way but in this way how i can pass float type value in the text box .This code is right working but not accept float value.
And other important thing is that , I want to do this for many comobox then in method how i can write code?
need help!
Karthik_Mahalingam 8-Aug-16 5:39am    
write a function and pass the parameters, and reuse it.
Member 12632487 8-Aug-16 6:59am    
How can pass the parameter. here is the confusion that how can pass the parameter for comobox no?
other thing is how can pass float value?
can you help me by writing small code?
Karthik_Mahalingam 8-Aug-16 7:48am    
float value means?
give some example of how ur data looks like and how to do you want to display in the screen
Member 12632487 8-Aug-16 8:51am    
same thing i want that you already discuse . mean when user select grade (like A+) then textbox can show (3.4)
as you show that when user select grade "A+" the textbox automatecally show 4
now i want that it can also show the float value like 3.4,4.2 etc

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900