private void HideChildrenRows(UCDataGridViewTreeRow row) { if (row.ChildrenRows.Count > 0) { foreach (var item in row.ChildrenRows) { HideChildrenRows(item); item.Hide(); } row.IsOpened = false; } }
private List <IDataGridViewRow> FindTreeRowSelected(UCDataGridViewTreeRow row) { List <IDataGridViewRow> lst = new List <IDataGridViewRow>(); var _lst = row.ChildrenRows.FindAll(p => p.IsChecked); lst.AddRange(_lst); foreach (UCDataGridViewTreeRow _row in row.ChildrenRows) { lst.AddRange(FindTreeRowSelected(_row)); } return(lst); }
/// <summary> /// Handles the MouseDown event of the panLeft control. /// </summary> /// <param name="sender">The source of the event.</param> /// <param name="e">The <see cref="MouseEventArgs" /> instance containing the event data.</param> private void panLeft_MouseDown(object sender, MouseEventArgs e) { try { if (!IsOpened.HasValue) { return; } ControlHelper.FreezeControl(this.FindForm(), true); if (!IsOpened.Value) { IsOpened = !IsOpened; if (childrenRows.Count > 0) { childrenRows.ForEach(p => { p.IsChecked = IsChecked; p.Visible = true; }); } else { var proChildrens = DataSource.GetType().GetProperty("Childrens"); if (proChildrens != null) { var value = proChildrens.GetValue(DataSource, null); int intSourceCount = 0; if (value is DataTable) { intSourceCount = (value as DataTable).Rows.Count; } else if (typeof(IList).IsAssignableFrom(value.GetType())) { intSourceCount = (value as IList).Count; } for (int i = intSourceCount - 1; i >= 0; i--) { UCDataGridViewTreeRow row = new UCDataGridViewTreeRow(); if (value is DataTable) { row.DataSource = (value as DataTable).Rows[i]; } else { row.DataSource = (value as IList)[i]; } row.RowLevel = RowLevel + 1; row.Columns = Columns; row.IsShowCheckBox = IsShowCheckBox; row.ReloadCells(); row.BindingCellData(); Control rowControl = (row as Control); row.RowHeight = m_rowHeight; rowControl.Width = this.Width; //rowControl.Dock = DockStyle.Top; row.CellClick += (a, b) => { CellClick(rowControl, b); }; row.CheckBoxChangeEvent += (a, b) => { CheckBoxChangeEvent(rowControl, b); }; row.RowCustomEvent += (a, b) => { if (RowCustomEvent != null) { RowCustomEvent(a, b); } }; row.SourceChanged += SourceChanged; ChildrenRows.Add(row); row.RowIndex = ChildrenRows.IndexOf(row); this.Parent.Controls.Add(rowControl); var index = this.Parent.Controls.GetChildIndex(this); this.Parent.Controls.SetChildIndex(row, index + 1); } } } } else { HideChildrenRows(this); this.Height = m_rowHeight; } } finally { ControlHelper.FreezeControl(this.FindForm(), false); } }