using System; using System.Reflection; using System.Windows.Forms; using Infragistics.Win; using Infragistics.Win.UltraWinGrid; namespace Core.Mes.Client.Comm.Control { public class ExtendedCheckBoxUIElement : CheckBoxUIElement { public ExtendedCheckBoxUIElement(UIElement parent) : base(parent) { this.ThreeState = false; } public override CheckState CheckState { get { return base.CheckState; } set { //CheckState checkState = this.CheckState; base.CheckState = value; //if (checkState != value) //{ // this.OnCheckStateChange(); //} } } protected override void OnCheckStateChange() { base.OnCheckStateChange(); ExtendedUltraGrid ultraGrid = this.Control as ExtendedUltraGrid; HeaderUIElement headerUIElement = this.GetAncestor(typeof(HeaderUIElement))as HeaderUIElement; UltraGridRow ultraGridRow = headerUIElement.GetContext(typeof(UltraGridRow))as UltraGridRow; UltraGridGroupByRow parentRow = ultraGridRow.ParentRow as UltraGridGroupByRow; if (null != parentRow) { parentRow.Tag = this.CheckState; this.SetAllGridRowSelected(parentRow.Rows, this.CheckState); } else { this.SetAllGridRowSelected((this.Control as UltraGrid).Rows, this.CheckState); } if (!ultraGrid.IsGroupMode) { ultraGrid.CheckState = this.CheckState; } } private void SetAllGridRowSelected(RowsCollection rows, CheckState state) { foreach (var row in rows) { if (row.IsGroupByRow) { row.Tag = this.CheckState; SetAllGridRowSelected(((UltraGridGroupByRow)row).Rows, state); } else { string selectAllColumnName = (this.Control as ExtendedUltraGrid).SelectAllColumnName; if (row.Activation == Activation.Disabled) continue; if (!row.Band.Columns.Exists(selectAllColumnName)) continue; if (row.Band.Columns[selectAllColumnName].CellActivation == Activation.Disabled) continue; if (null == row.Cells) continue; if (Convert.ToBoolean(row.Cells[selectAllColumnName].Value) != Convert.ToBoolean(state)) { row.Cells[selectAllColumnName].Value = state; (this.Control as ExtendedUltraGrid).ChangeCell(row.Cells[selectAllColumnName]); } row.Update(); } } } } }