ExtendedCheckBoxUIElement.cs 2.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. using System;
  2. using System.Reflection;
  3. using System.Windows.Forms;
  4. using Infragistics.Win;
  5. using Infragistics.Win.UltraWinGrid;
  6. namespace Core.Mes.Client.Comm.Control
  7. {
  8. public class ExtendedCheckBoxUIElement : CheckBoxUIElement
  9. {
  10. public ExtendedCheckBoxUIElement(UIElement parent)
  11. : base(parent)
  12. {
  13. this.ThreeState = false;
  14. }
  15. public override CheckState CheckState
  16. {
  17. get
  18. {
  19. return base.CheckState;
  20. }
  21. set
  22. {
  23. //CheckState checkState = this.CheckState;
  24. base.CheckState = value;
  25. //if (checkState != value)
  26. //{
  27. // this.OnCheckStateChange();
  28. //}
  29. }
  30. }
  31. protected override void OnCheckStateChange()
  32. {
  33. base.OnCheckStateChange();
  34. ExtendedUltraGrid ultraGrid = this.Control as ExtendedUltraGrid;
  35. HeaderUIElement headerUIElement = this.GetAncestor(typeof(HeaderUIElement))as HeaderUIElement;
  36. UltraGridRow ultraGridRow = headerUIElement.GetContext(typeof(UltraGridRow))as UltraGridRow;
  37. UltraGridGroupByRow parentRow = ultraGridRow.ParentRow as UltraGridGroupByRow;
  38. if (null != parentRow)
  39. {
  40. parentRow.Tag = this.CheckState;
  41. this.SetAllGridRowSelected(parentRow.Rows, this.CheckState);
  42. }
  43. else
  44. {
  45. this.SetAllGridRowSelected((this.Control as UltraGrid).Rows, this.CheckState);
  46. }
  47. if (!ultraGrid.IsGroupMode)
  48. {
  49. ultraGrid.CheckState = this.CheckState;
  50. }
  51. }
  52. private void SetAllGridRowSelected(RowsCollection rows, CheckState state)
  53. {
  54. foreach (var row in rows)
  55. {
  56. if (row.IsGroupByRow)
  57. {
  58. row.Tag = this.CheckState;
  59. SetAllGridRowSelected(((UltraGridGroupByRow)row).Rows, state);
  60. }
  61. else
  62. {
  63. string selectAllColumnName = (this.Control as ExtendedUltraGrid).SelectAllColumnName;
  64. if (row.Activation == Activation.Disabled) continue;
  65. if (!row.Band.Columns.Exists(selectAllColumnName)) continue;
  66. if (row.Band.Columns[selectAllColumnName].CellActivation == Activation.Disabled) continue;
  67. if (null == row.Cells) continue;
  68. if (Convert.ToBoolean(row.Cells[selectAllColumnName].Value) != Convert.ToBoolean(state))
  69. {
  70. row.Cells[selectAllColumnName].Value = state;
  71. (this.Control as ExtendedUltraGrid).ChangeCell(row.Cells[selectAllColumnName]);
  72. }
  73. row.Update();
  74. }
  75. }
  76. }
  77. }
  78. }