Foreach at a checklist in c#

Asked

Viewed 76 times

5

private void Checked()
{
    foreach (ListViewItem listItem in listView.Items)
    {
        if (cb_selectAll.Checked == true)
        {
            listItem.Checked = true;
        }
        if (cb_selectAll.Checked == false)
        {
            listItem.Checked = false;
        }
    }
}

I have this code here. Only in the foreach is giving the following error:

Cannot Convert type 'Infragistics.Win.Ultrawinlistview.Ultralistviewitem' to System.Windows.Forms.Listviewitem.

How can I eliminate that mistake?

The list view looks like this :

private void Search()
{
    mUpdater = new DatabaseUpdaterService();

    mUpdater.Initialize(false, null);

    DataTable dt = mUpdater.GetVersionCheckBoxToUpdate();

    foreach (DataRow row in dt.Rows)
    {
        this.listView.Items.Add(row["ID"].ToString(), row["Version"].ToString());
    }
}

2 answers

7


The mistake is very clear, listView.Items is a collection of UltraListViewItem.

To ListView that is being used is not the default of Winforms but a proper implementation.

Without further details, the solution I can propose is to change the foreach to look like this

foreach (UltraListViewItem listItem in listView.Items)

Anyway, it is still possible to use var and let the type be set automatically, thus

foreach (var listItem in listView.Items)     
  • thank you very much. I’m still new at this.

1

For those who want the solution is here:

UltraListViewSubItem subItem;
List<UltraListViewSubItem> subItemArray;
UltraListViewItem item = new UltraListViewItem(
                row["Version"].ToString(), subItemArray.ToArray());
                item.Key = row["ID"].ToString();

Browser other questions tagged

You are not signed in. Login or sign up in order to post.