Reputation: 263
In the constructor:
lvnf = new ListViewNF();
lvnf.Location = new Point(250, 18);
lvnf.Size = new Size(474, 168);
this.Controls.Add(lvnf);
After setting the size i want to add columns like: From Subject Date
And how do i set the listView control(lvnf) to display added items as list ? This is how i'm adding the items in progressChanged event:
private void backgroundWorker1_ProgressChanged(object sender, ProgressChangedEventArgs e)
{
pbt.Value = e.ProgressPercentage;
pbt.Text = e.ProgressPercentage.ToString() + "%";
pbt.Invalidate();
label8.Text = e.UserState.ToString();
label8.Visible = true;
lvnf.Items.Add(new ListViewItem(new string[]
{
allMessages[countMsg].Headers.From.ToString(), //From Column
allMessages[countMsg].Headers.Subject, //Subject Column
allMessages[countMsg].Headers.DateSent.ToString() //Date Column
}));
countMsg += 1;
}
Upvotes: 1
Views: 41
Reputation: 15982
You can add columns to ListView
by adding it to the Columns
property:
lvnf.Columns.Add("From");
lvnf.Columns.Add("Subject");
lvnf.Columns.Add("Date");
And to display items as a list:
lvnf.View = View.List;
But if you use this view, column headers will be hidden.
Upvotes: 0
Reputation: 90
You can use the ListView to get columns with headers. One of the properties is the View, and you set it to Details, I think. Then you add columns
listView1.Columns.Add("Column1",100); // 100 is the column width
listView1.Columns.Add("Column2",200);
and so on for each column.
To add an item,
listView1.Items.Add("First item");
Then to add the subitems (in the columns) for the ith them
listView1.Items[i].SubItems.Add("Subitem1");
For the first item, this would be
listView1.Items[0].SubItems.Add("Subitem1");
Hope this helps.
Upvotes: 2