Foreach in a CheckList in C #

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. But in foreach it is giving the following error:

  

Can not convert type 'Infragistics.Win.UltraWinListView.UltraListViewItem' to System.Windows.Forms.ListViewItem.

How can I eliminate this error?

The View list 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());
    }
}
    
asked by anonymous 04.05.2017 / 17:22

2 answers

7

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

The ListView being used is not the WinForms standard, but rather a stand-alone implementation.

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

foreach (UltraListViewItem listItem in listView.Items)

Anyway, you can still use var and let the type be set automatically, so

foreach (var listItem in listView.Items)     
    
04.05.2017 / 17:29
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();
    
28.06.2017 / 10:29