Advertisement
Guest User

Untitled

a guest
Jul 26th, 2017
49
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.64 KB | None | 0 0
  1. binding = new Binding("Text", cmb_PrefConNumber, "Text");
  2. cmb_PrefConNumber.DataBindings.Add(binding);
  3.  
  4. if (!cmb_PrefConNumber.Items.Contains("Alternative"))
  5. {
  6. cmb_PrefConNumber.Items.Add("Alternative");
  7. return;
  8. }
  9.  
  10. private void textBox1_TextChanged(object sender, EventArgs e)
  11. {
  12. if(!String.IsNullOrEmpty(textBox1.Text))
  13. {
  14. PopulateCombo(1);
  15. }
  16. }
  17.  
  18. private void textBox2_TextChanged(object sender, EventArgs e)
  19. {
  20. if(!String.IsNullOrEmpty(textBox1.Text))
  21. {
  22. PopulateCombo(2);
  23. }
  24. }
  25.  
  26. private void textBox3_TextChanged(object sender, EventArgs e)
  27. {
  28. if(!String.IsNullOrEmpty(textBox1.Text))
  29. {
  30. PopulateCombo(3);
  31. }
  32. }
  33.  
  34. private void PopulateCombo(int textBoxID)
  35. {
  36. //With this you will get how many textBoxes have value
  37. int filledTextboxes = 0;
  38. filledTextboxes = (String.IsNullOrEmpty(textBox1.Text)) ? filledTextboxes++ : filledTextboxes;
  39. filledTextboxes = (String.IsNullOrEmpty(textBox2.Text)) ? filledTextboxes++ : filledTextboxes;
  40. filledTextboxes = (String.IsNullOrEmpty(textBox3.Text)) ? filledTextboxes++ : filledTextboxes;
  41.  
  42. //With this you will run one code if only one textbox has value and other if more than one has value
  43. if(filledTextboxes == 1)
  44. {
  45. switch(textBoxID)
  46. {
  47. case 1:
  48. //Populate comboBox with some value
  49. break;
  50. case 2:
  51. //Populate comboBox with some value
  52. break;
  53. case 3:
  54. //Populate comboBox with some value
  55. break;
  56. }
  57. }
  58. else
  59. {
  60. //What happends when there are multiple textbox with value
  61. }
  62. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement