Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

C# disable a checkbox based on run-time textbox user input value

I have two textbox to let user input start date and end date. Then I have a checkbox that allow user to check to see some calculations. My question is, how can I disable the checkbox if the duration between start date and end date is shorter than a specific length. I mean, right after user input the start date and end date, he/she would see the checkbox is disabled because the time period length is not long enough.

if (productWealth.Count < 3)
    checkBox7.Enabled = false;

This is what I have now, if count < 3, then checkbox 7 is disabled. Seems like the application only run the count when run click the RUN button, but I want them to see immediate effect.

like image 904
Eddie Avatar asked Nov 02 '22 14:11

Eddie


1 Answers

You can use the event TextChanged, so when the user change the value of the TextBox you check if its true and enable the CheckBox.

tboxEndDate.TextChanged += new TextChangedEventHandler(tboxEndDate_TextChanged);

void tboxEndDate_TextChanged(object sender, TextChangedEventArgs e)
{
   // Calcule the productWealth
   if (productWealth.Count < 3) checkBox7.Enabled = false;
}
like image 166
Butzke Avatar answered Nov 09 '22 06:11

Butzke