Check checked item

Asked

Viewed 239 times

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 stays checked. How could I do so when the same checkbox that was clicked performs another operation as soon as it receives another click? That would remove the marking.

  • tried to use the Selectedindexchanged event? Because it is thus possible to check whether the item has been marked or not if it has been marked executes this code snippet if not.. does what you need to do.

  • I even tried, but when I installed listview, it says that his checkbox is read-only.

1 answer

0


You have the option of using Itemcheckedeventargs by referencing "and", so you can access the properties of the item that received the click:

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

Or you scroll through all the Listview items and arrow the value for each one

foreach(var i in listView1.Items)
{
   ListViewItem listViewItem = (ListViewItem)i;
   SetValueInDatabase(listViewItem.Checked);
}
  • I will try to implement in need here. Obg Renan

Browser other questions tagged

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