public void Populate() { listView.Items.Clear(); listView.Groups.Clear(); if (ArchiveWriters != null && ArchiveWriters.Count > 0) { ListViewGroup group = new ListViewGroup("Archive Writers"); listView.Groups.Add(group); foreach (IPlugin plugin in ArchiveWriters) { AddItem(plugin, ArchiveWriterType, group); } } if (MetadataConverters != null && MetadataConverters.Count > 0) { ListViewGroup group = new ListViewGroup("Metadata Converters"); listView.Groups.Add(group); foreach (IPlugin plugin in MetadataConverters) { AddItem(plugin, MetadataConverterType, group); } } if (MetadataProcessors != null && MetadataProcessors.Count > 0) { ListViewGroup group = new ListViewGroup("Metadata Processors"); listView.Groups.Add(group); foreach (IPlugin plugin in MetadataProcessors) { AddItem(plugin, MetadataProcessorType, group); } } listView.AutoResizeColumns(ColumnHeaderAutoResizeStyle.ColumnContent); listView.AutoResizeColumns(ColumnHeaderAutoResizeStyle.HeaderSize); }
private void Initial_ListView(object obj) { DataTable capacity_dt = obj as DataTable; int Listview_count = 0; int Average_count = 0; if (capacity_dt.TableName == "模拟传感器") { Listview_count = 4; } else { Listview_count = 3; } Average_count = capacity_dt.Rows.Count / Listview_count; try { if (!this.IsHandleCreated || this.IsDisposed) { return; } if (InvokeRequired) { this.Invoke((MethodInvoker) delegate { for (int i = 0; i < Listview_count + 1; i++) { ListViewEx lv = new ListViewEx(); lv.Height = Analog_flowpanel.Height - 10; lv.Width = (tabControl1.Width / (Listview_count + 1)) - 15; lv.View = View.Details; lv.FullRowSelect = true; lv.HeaderStyle = ColumnHeaderStyle.Clickable; lv.View = View.Details; lv.SmallImageList = this.imageList1; //将listView的图标集与imageList1绑定 lv.CheckBoxes = true; lv.View = View.Details; lv.GridLines = true; //显示网格线 lv.Items.Clear(); //所有的项 lv.Columns.Clear(); //标题 lv.Columns.Add("容量选择", 120, HorizontalAlignment.Left); //增加标题 lv.AutoResizeColumns(ColumnHeaderAutoResizeStyle.HeaderSize); //调整列的宽度 lv.ItemChecked += new System.Windows.Forms.ItemCheckedEventHandler(this.listViewEx_ItemChecked); if (capacity_dt.TableName == "模拟传感器") { Analog_flowpanel.Controls.Add(lv); } else { Digital_flowpanel.Controls.Add(lv); } for (int j = i * Average_count; j < (i + 1) * Average_count; j++) { if (j < (i + 1) * Average_count && j < capacity_dt.Rows.Count) { if (string.IsNullOrEmpty(Convert.ToString(capacity_dt.Rows[j][0]))) { UIHelper.ToastNotify(false, "有容量为空!", tabControl1); } ListViewItem lvi = new ListViewItem(capacity_dt.Rows[j][0].ToString()); lvi.ImageIndex = 0; if (old_capacity_str.Contains(lvi.Text.Replace("-", ""))) { lvi.Checked = true; } lv.Items.Add(lvi); //进度条 progressBarX1.Value += 1; progressBarX1.Text = ((double)progressBarX1.Value / progressBarX1.Maximum).ToString("P"); if (progressBarX1.Value == progressBarX1.Maximum) { progressBarX1.Visible = false; } Application.DoEvents(); } else { break; } } } }); } } catch (Exception ex) { Log4netHelper.Fatal(this.GetType(), "初始化Listview时异常:" + ex.Message); throw ex; } }