Reputation: 3003
How to add checked items to listView?
in .net2 window form
this sample works, but items are not checked
listView.Items.Add(
new ListViewItem(new string[] { folderBrowser.SelectedPath }, group_1));
this sample doesn't work, i want to add checked items
listView.Items.Add(
new ListViewItem(
new string[] { folderBrowser.SelectedPath },
group_1))
.Checked(true);
thankyou.
Upvotes: 1
Views: 1624
Reputation: 244767
If you're using C# 3 or newer (Visual Studio 2008 or newer), you can use object initializer:
listView.Items.Add(
new ListViewItem(
new string[] { folderBrowser.SelectedPath },
group_1))
{ Checked = true };
Upvotes: 0
Reputation: 2758
ListViewItem lvi = new ListViewItem(new string[] { folderBrowser.SelectedPath }, group_1);
lvi.Checked = true;
listView.Items.Add(lvi);
Upvotes: 1