User6996
User6996

Reputation: 3003

Add check items to listView

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

Answers (2)

svick
svick

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

therealmitchconnors
therealmitchconnors

Reputation: 2758

ListViewItem lvi = new ListViewItem(new string[] { folderBrowser.SelectedPath }, group_1);
lvi.Checked = true;
listView.Items.Add(lvi);

Upvotes: 1

Related Questions