user7115125
user7115125

Reputation:

Items aren't showing up in ListView

So, I created a ListView and am currently trying to add items once a button is clicked. But, that doesn't seem to be working for me: the items I'm adding (at least that's what I think I'm doing) aren't showing up in the ListView. What seems to be the problem here? Any and all help would be appreciated.

Methods

private void setListViewItem(string value) {
    ListViewItem item = new ListViewItem(value);
    this.listView1.Items.Add(item);
}

private void button1_Click(object sender, EventArgs e) {
    setListViewItem(textBox1.Text);
}

ListView properties

this.listView1.Columns.AddRange(new System.Windows.Forms.ColumnHeader[] {this.columnHeader1});
this.listView1.Location = new System.Drawing.Point(13, 87);
this.listView1.Name = "listView1";
this.listView1.Size = new System.Drawing.Size(277, 91);
this.listView1.TabIndex = 9;
this.listView1.UseCompatibleStateImageBehavior = false;
this.listView1.View = System.Windows.Forms.View.Details;

Upvotes: 0

Views: 81

Answers (2)

abdul
abdul

Reputation: 1582

You need to add columns to make your data show up since you have listView1.View set to Details, if you set listView1.View to List, it will work without having to add columns.

You can check this example ListView.View to see how to add data into a Detail view.

Upvotes: 1

Krekkon
Krekkon

Reputation: 1347

You forgot to populate the ItemSource. Please check this link, it should help: ListView, data binding and ItemTemplate

Upvotes: 0

Related Questions