public void AddItem(ListEditViewItem items) { if (items.Items.Count != this.ListViewCustom.Columns.Count) { throw new Exception("你提供的数据列数与标题列的数目不同"); } for (int i = 0; i < items.Items.Count; i++) { EditViewColumnHeader header = this.ListViewCustom.Columns[i] as EditViewColumnHeader; string text = ""; if (header.ColumnStyle == ListEditViewColumnStyle.Control) { if (!(items.Items[i] is Control)) { throw new Exception("列数据类型不正确!"); } this.ListViewCustom.Controls.Add(items.Items[i] as Control); } else { text = items.Items[i].ToString(); } if (i > 0) { ListViewItem.ListViewSubItem item = new ListViewItem.ListViewSubItem(items, text); items.SubItems.Add(item); } } this.Items.Add(items); this.ListViewCustom.Items.Add(items); this.MoveControl(); }
private void MoveControl() { for (int i = 0; i < this.ListViewCustom.Items.Count; i++) { ListEditViewItem item = this.ListViewCustom.Items[i] as ListEditViewItem; for (int j = 0; j < this.ListViewCustom.Columns.Count; j++) { Point point; Size size; EditViewColumnHeader header = this.ListViewCustom.Columns[j] as EditViewColumnHeader; if (item.SubItems[j].Bounds.Y <= 5) { point = new Point(item.SubItems[j].Bounds.X, item.SubItems[j].Bounds.Y - 20); } else { point = new Point(item.SubItems[j].Bounds.X, item.SubItems[j].Bounds.Y); } if ((j == 0) && (this.ListViewCustom.Columns.Count > 1)) { size = new Size(item.SubItems[1].Bounds.X - item.SubItems[0].Bounds.X, item.SubItems[j].Bounds.Height); } else { size = new Size(item.SubItems[j].Bounds.Width, item.SubItems[j].Bounds.Height); } if (header.ColumnStyle == ListEditViewColumnStyle.Control) { Control control = item.Items[j] as Control; control.Location = point; control.Size = size; } } } }
private void DelControl(ListEditViewItem items) { ListEditViewItem item = items; for (int i = 0; i < this.ListViewCustom.Columns.Count; i++) { EditViewColumnHeader header = this.ListViewCustom.Columns[i] as EditViewColumnHeader; if (header.ColumnStyle == ListEditViewColumnStyle.Control) { (item.Items[i] as Control).Dispose(); } } }
public void DeleteItem(ListEditViewItem items) { this.Items.Remove(items); this.ListViewCustom.Items.Remove(items); this.MoveControl(); }