初始化
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
private void ListViewReset() { listView1.MultiSelect = true; listView1.Scrollable = true; listView1.View = View.Details; listView1.GridLines = true; listView1.FullRowSelect = true; listView1.HideSelection = true; }
ColumnHeader
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
ColumnHeader ch = new ColumnHeader(); ch.Text = "序号"; ch.Width = 40; listView1.Columns.Add(ch); ch = new ColumnHeader(); ch.TextAlign = HorizontalAlignment.Center; ch.Text = "编码"; ch.Width = 70; listView1.Columns.Add(ch); ch = new ColumnHeader(); ch.TextAlign = HorizontalAlignment.Center; ch.Text = "商品名"; ch.Width = 160; listView1.Columns.Add(ch); ch = new ColumnHeader(); ch.TextAlign = HorizontalAlignment.Center; ch.Text = "进价"; ch.Width = 70; listView1.Columns.Add(ch); ch = new ColumnHeader(); ch.TextAlign = HorizontalAlignment.Center; ch.Text = "卖价"; ch.Width = 70; listView1.Columns.Add(ch); ch = new ColumnHeader(); ch.TextAlign = HorizontalAlignment.Center; ch.Text = "盘点数"; ch.Width = 70; listView1.Columns.Add(ch); ch = new ColumnHeader(); ch.TextAlign = HorizontalAlignment.Center; ch.Text = "盘点单号"; ch.Width = 120; listView1.Columns.Add(ch); ch = new ColumnHeader(); ch.TextAlign = HorizontalAlignment.Center; ch.Text = "异常"; ch.Width = 80; listView1.Columns.Add(ch);
ListViewItem
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
ListViewItem item = new ListViewItem(); item.Text = num.ToString(); item.Tag = models[i]; ListViewItem.ListViewSubItem subitem = new ListViewItem.ListViewSubItem(); subitem.Text = models[i].Item_no.Trim(); item.SubItems.Add(subitem); subitem = new ListViewItem.ListViewSubItem(); subitem.Text = models[i].Item_name; item.SubItems.Add(subitem); subitem = new ListViewItem.ListViewSubItem(); subitem.Text = models[i].Inprice; item.SubItems.Add(subitem); subitem = new ListViewItem.ListViewSubItem(); subitem.Text = models[i].Sale_price; if (decimal.Parse(subitem.Text) <= 0) { item.BackColor = Color.Red; exSubitem.Text = "售价异常!"; } item.SubItems.Add(subitem); subitem = new ListViewItem.ListViewSubItem(); subitem.Text = models[i].Real_qty; if (decimal.Parse(subitem.Text) <= 0) { item.BackColor = Color.Red; exSubitem.Text = "库存异常!"; } item.SubItems.Add(subitem); subitem = new ListViewItem.ListViewSubItem(); subitem.Text = models[i].Sheet_no; item.SubItems.Add(subitem); ListViewItem.ListViewSubItem exSubitem = new ListViewItem.ListViewSubItem(); exSubitem.Text = ""; item.SubItems.Add(exSubitem); item.Tag = models[i]; this.listView1.Items.Add(item);