ListView 控件 添加多列 自定义列

 ColumnHeader ch = new ColumnHeader();
            ch.Text = "控制机列表";
            ColumnHeader weizhi = new ColumnHeader();
            weizhi.Text = "控制机位置";

            ColumnHeader Ipadress = new ColumnHeader();
            Ipadress.Text = "IP地址";

            ch.TextAlign = HorizontalAlignment.Left;
            ch.Width = 150;
            weizhi.Width = 100;
            Ipadress.Width = 200;
            lvDevc.Columns.Add(ch);
            lvDevc.Columns.Add(weizhi);
            lvDevc.Columns.Add(Ipadress);
           // lvDevc.LargeImageList = this.imageList1;
            // label9.Text = "控制机信息加载中.....";
            BLL.ControllerParamSet bll = new BLL.ControllerParamSet();
            this.lvDevc.BeginUpdate();

            for (int i = 0; i < bll.GetTablePlaceDevcNumber().Rows.Count; i++)// 控制机树的加载
            {
                ListViewItem lvi = new ListViewItem(bll.GetTablePlaceDevcNumber().Rows[i][0].ToString());
              //  lvi.Text = bll.GetTablePlaceDevcNumber().Rows[i][0].ToString() + bll.GetTablePlaceDevcNumber().Rows[i][1].ToString();
                lvi.SubItems[0].Text=bll.GetTablePlaceDevcNumber().Rows[i][0].ToString();
                lvi.SubItems.Add (bll.GetTablePlaceDevcNumber().Rows[i][1].ToString());
                lvi.SubItems.Add( bll.GetTablePlaceDevcNumber().Rows[i][2].ToString());
                lvi.ImageIndex = 0;
                this.lvDevc.Items.Add(lvi);
            }
            this.lvDevc.EndUpdate();

你可能感兴趣的:(C#,vs2010,实例)