Check item checked

0

I have the following code inside the Itemchecked event:

private void lsvRecebeGrupoLayout_ItemChecked(object sender, ItemCheckedEventArgs e)
{
    Layout lay = new Layout();
    GrupoLayout grupo = new GrupoLayout();
    RepositorioGrupoLayout rgl = new RepositorioGrupoLayout();
    RepositorioLayout repolay = new RepositorioLayout();
    int idcbo = Convert.ToInt32(cboCarregaGrupo.SelectedValue);
    foreach (ListViewItem x in lsvRecebeGrupoLayout.CheckedItems)
    {
        int idlayout = Convert.ToInt32(x.SubItems[0].Text);
        lay = repolay.ConsultaPorId(idlayout);
        grupo.Id = idcbo;
        lay.GrupoLayout = grupo;

        if (x.Checked)
        {
            repolay.Alterar(lay);
        }       
    }
}

When the checkbox is clicked it makes a change in the bank and remains checked. How could I do that when the same checkbox that was clicked performs another operation as soon as it receives another click? That would remove the markup.

    
asked by anonymous 11.10.2017 / 18:48

1 answer

0

You have the option of using ItemCheckedEventArgs by referencing the "e", so you can access the properties of the item you clicked on:

e.Item.Checked;
e.Item.Index;
e.Item.Name;

Or you go through all the items in the ListView and arrow the value for each

foreach(var i in listView1.Items)
{
   ListViewItem listViewItem = (ListViewItem)i;
   SetValueInDatabase(listViewItem.Checked);
}
    
12.10.2017 / 08:29