public TableItemBase LastClickItem = null; // 最近一次click选择过的Item对象 public void SelectItem(TableItemBase element, bool bClearOld) { if (bClearOld == true) { for (int i = 0; i < this.Items.Count; i++) { TableItemBase cur_element = this.Items[i]; if (cur_element == element) { continue; // 暂时不处理当前行 } if ((cur_element.State & ItemState.Selected) != 0) { cur_element.State -= ItemState.Selected; this.InvalidateLine(cur_element); } } } // 选中当前行 if ((element.State & ItemState.Selected) == 0) { element.State |= ItemState.Selected; this.InvalidateLine(element); } this.LastClickItem = element; }
void RefreshLineColor() { for (int i = 0; i < this.Items.Count; i++) { TableItemBase item = this.Items[i]; item.SetLineColor(); } }
public void RangeSelectItem(TableItemBase element) { TableItemBase start = this.LastClickItem; int nStart = this.Items.IndexOf(start); if (nStart == -1) { return; } int nEnd = this.Items.IndexOf(element); if (nStart > nEnd) { // 交换 int nTemp = nStart; nStart = nEnd; nEnd = nTemp; } for (int i = nStart; i <= nEnd; i++) { TableItemBase cur_element = this.Items[i]; if ((cur_element.State & ItemState.Selected) == 0) { cur_element.State |= ItemState.Selected; this.InvalidateLine(cur_element); } } // 清除其余位置 for (int i = 0; i < nStart; i++) { TableItemBase cur_element = this.Items[i]; if ((cur_element.State & ItemState.Selected) != 0) { cur_element.State -= ItemState.Selected; this.InvalidateLine(cur_element); } } for (int i = nEnd + 1; i < this.Items.Count; i++) { TableItemBase cur_element = this.Items[i]; if ((cur_element.State & ItemState.Selected) != 0) { cur_element.State -= ItemState.Selected; this.InvalidateLine(cur_element); } } }
public void SelectAll() { for (int i = 0; i < this.Items.Count; i++) { TableItemBase cur_element = this.Items[i]; if ((cur_element.State & ItemState.Selected) == 0) { cur_element.State |= ItemState.Selected; } } this.Invalidate(); }
internal void InvalidateLine(TableItemBase item) { Point p = this.tableLayoutPanel_content.PointToScreen(new Point(0, 0)); Rectangle rect = item.label_color.RectangleToScreen(item.label_color.ClientRectangle); rect.Width = this.tableLayoutPanel_content.DisplayRectangle.Width; rect.Offset(-p.X, -p.Y); rect.Height = (int)this.Font.GetHeight() + 8; // 缩小刷新高度 this.tableLayoutPanel_content.Invalidate(rect, false); // this.tableLayoutPanel_content.Invalidate(); }
public void ToggleSelectItem(TableItemBase element) { // 选中当前行 if ((element.State & ItemState.Selected) == 0) { element.State |= ItemState.Selected; } else { element.State -= ItemState.Selected; } this.InvalidateLine(element); this.LastClickItem = element; }
// 将全部行的状态恢复为普通状态 void ResetLineState() { for (int i = 0; i < this.Items.Count; i++) { TableItemBase item = this.Items[i]; if ((item.State & ItemState.ReadOnly) != 0) { item.State = ItemState.Normal | ItemState.ReadOnly; } else { item.State = ItemState.Normal; } } this.Invalidate(); }
public void InsertNewLine(int index, TableItemBase line, bool bFireEnvent) { this.DisableUpdate(); // 防止闪动 try { #if NO RowStyle style = new RowStyle(); //style.Height = 26; //style.SizeType = SizeType.Absolute; this.tableLayoutPanel_content.RowStyles.Insert(index + RESERVE_LINES, style); #endif Debug.Assert(this.tableLayoutPanel_content.RowStyles.Count == 1, ""); this.tableLayoutPanel_content.RowCount += 1; Debug.Assert(this.tableLayoutPanel_content.RowStyles.Count == 1, ""); line.InsertToTable(this.tableLayoutPanel_content, index); this.Items.Insert(index, line); line.State = ItemState.New; if (bFireEnvent == true) { this.FireTextChanged(); } Debug.Assert(this.tableLayoutPanel_content.RowStyles.Count == 1, ""); } finally { this.EnableUpdate(); } }