c#:如图,winform如何把几个textbox的内容添加到listview里?还有listview的列名怎么改才起效?求指点

2025-01-01 01:08:19
推荐回答(2个)
回答1:

private void button1_Click(object sender, EventArgs e)
        {
            ListViewItem lvi = addListView();
            this.listView1.Items.Add(lvi);
            this.listView1.Refresh();
        }
        private ListViewItem addListView()
        {
            ListViewItem lvi = new ListViewItem(this.textBox1.Text);
            lvi.SubItems.Add(this.textBox2.Text);
            lvi.SubItems.Add(this.textBox3.Text);
            lvi.SubItems.Add(this.textBox4.Text);
            return lvi;
        }
        private void Form1_Load(object sender, EventArgs e)
        {
            this.listView1.Clear();
            ColumnHeader header1 = new ColumnHeader();
            header1.Text = "学号";
            ColumnHeader header2 = new ColumnHeader();
            header2.Text = "姓名";
            ColumnHeader header3 = new ColumnHeader();
            header3.Text = "班级";
            ColumnHeader header4 = new ColumnHeader();
            header4.Text = "电话";
            this.listView1.Columns.AddRange(new ColumnHeader[] { header1, header2, header3, header4 });
            this.listView1.GridLines = true;
            this.listView1.View = View.Details;
            this.listView1.FullRowSelect = true;
        }

回答2:

是否没设置下面的属性?
this.listView1.View = View.Details;