Click here to Skip to main content
15,908,254 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more: , +
Can any body help me to solve this
when i select a item from combobox how can i change the back color of my text box(used to show quantity) when the quantity became less than 5 .
Posted

1 solution

That' basically the same as my previous answer: (quantity is taken from the textBox, but can also be taken from the combobox by replacing textBox2.Text with comboBox1.SelectedItem.ToString())
C#
private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)
{
  int quantity = 0;
  if (!Int32.TryParse(textBox2.Text, out quantity))
  {
    textBox2.BackColor = Color.Red;
    return;
  }
  if (quantity < 5)
    textBox2.BackColor = Color.Green;
  else
    textBox2.BackColor = Color.White;
}
 
Share this answer
 
v2
Comments
sevenbell 3-Feb-11 3:09am    
its not working .
JF2015 3-Feb-11 3:15am    
If that is not working, you need to be more specific in what you are trying to achieve. You could also show us some code and tell us what exactly is not working.
JF2015 3-Feb-11 3:28am    
This code does not make a lot of sense. I don't understand why you loop over each datarow in your table since you overwrite the content of the textboxes (3 and 18) with the datarow values. You need to be more specific in telling us what you want to achieve. What do you want to be displayed in the textboxes?
JF2015 3-Feb-11 3:46am    
But that doesn't make sense if you overwrite the textBox18.Text and textBox3.Text values in a loop.
JF2015 3-Feb-11 4:23am    
If you loop through the datarows, it does not make sense to add each rows values to a textBox. You should use a listview or a gridview instead.

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