日期:2014-05-17  浏览次数:20797 次

ListView控件
     ColumnHeader h1 = new ColumnHeader();//创建一个列
            h1.Text = "姓名";

            ColumnHeader h2 = new ColumnHeader();//创建第二个列
            h2.Text = "学号";
            listView1.Columns.AddRange(new ColumnHeader[]{h1,h2});//将列添加到空间里
            listView1.View = View.Details;//列的显示模式
            ListViewItem l = new ListViewItem(new string[]{"张三","14"});//实例化一个元素
            listView1.Items.Add(l);//将实例化的数据添加到 控件里


启动时,为啥显示的是3列呢第一列是姓名,第二列是学好,怎么还有个第三列空的。。。。只需要两列的,谢谢大家

------解决方案--------------------

首先初始化listview控件:
private void SetListView()
        {
            // Set the view to show details.
            listView1.View = View.Details;
            // Allow the user to edit item text.
            listView1.LabelEdit = false;
            // Allow the user to rearrange columns.
            listView1.AllowColumnReorder = false;
            // Select the item and subitems when selection is made.
            listView1.FullRowSelect = true;
            // Display grid lines.
            listView1.GridLines = true;
            // Sort the items in the list in descending order.
            listView1.Sorting = SortOrder.None;
             
            // Create columns for the items and subitems.
            listView1.Columns.Add("roomTem", "环境温度(℃)");
            listView1.Columns.Add("DC", "直流跳闸时间(s)");
            listView1.Columns.Add("exchange", "交流跳闸时间(s)");
 
            int width = listView1.Width / 3;
             
            listView1.Columns["roomTem"].Width = w