Guest User

Untitled

a guest
Aug 20th, 2018
78
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.41 KB | None | 0 0
  1. Setting a value in DataTable fires SelectedIndexChanged event
  2. private void richTextBox1_TextChanged(object sender, EventArgs e)
  3. {
  4. if (listBox1.SelectedIndex != -1)
  5. {
  6. dataSet11.Notes.Rows[listBox1.SelectedIndex]["Text"] = richTextBox1.Text;
  7. //this line fires listBox1_SelectedIndexChanged event
  8. //with listBox1.SelectedIndex = -1
  9. //then it changes listBox1.SelectedIndex back to original value before complete execution, and calls the even again
  10. }
  11. }
  12.  
  13. private void listBox1_SelectedIndexChanged(object sender, EventArgs e)
  14. {
  15.  
  16. }
  17.  
  18. private TextBox_OntextChanged(object sender, EventArgs args)
  19. {
  20. this.supressEvents = true;
  21. //Do your stuff here
  22. this.supressEvents = false;
  23. }
  24.  
  25. private void ListBox_OnSelectionChanged(object sender, EventArgs args)
  26. {
  27. if (this.supressEvents)
  28. {
  29. return;
  30. }
  31.  
  32. //Do your stuff here
  33. }
  34.  
  35. private void richTextBox1_TextChanged(object sender, EventArgs e)
  36. {
  37. listBox1.SelectedIndexChanged -= listBox1_SelectedIndexChanged;
  38. if (listBox1.SelectedIndex != -1)
  39. {
  40. dataSet11.Notes.Rows[listBox1.SelectedIndex]["Text"] = richTextBox1.Text;
  41. //this line fires listBox1_SelectedIndexChanged event
  42. //with listBox1.SelectedIndex = -1
  43. //then it changes listBox1.SelectedIndex back to original value before complete execution, and calls the even again
  44. }
  45. listBox1.SelectedIndexChanged += listBox1_SelectedIndexChanged;
  46. }
Add Comment
Please, Sign In to add comment