I'm loading some text into my listview lvPersons
what I want to do is, if in the column with index 0 have the value 1 the checkbox is checked if its 0 is unchecked and when I click in the checkbox it should check and uncheck but at the same time change to value to 0 or 1 but I can't do this, because when I give a load the it replaces the 1 to 0 and uncheck all the checkboxes my code is the follow:
private void btnLoadList_Click(object sender, EventArgs e)
{
//My load funcion is here
//This code after the load if getting skipped to private void lvPersons_ItemChecked(object sender, ItemCheckedEventArgs e) so this one is not executing after the load of items
foreach (ListViewItem ActiveItem in lvPersons.Items)
{
if (ActiveItem.SubItems[0].Text == "1")
{
ActiveItem.Checked = true;
}
}
}
#endregion
private void lvPersons_ItemChecked(object sender, ItemCheckedEventArgs e)
{
foreach (ListViewItem CheckChangeNow in lvPersons.Items)
{
//This code here is the same that is up in the button but with this one here they will appear check but they will not uncheck
if (CheckChangeNow.SubItems[0].Text == "1")
{
CheckChangeNow.Checked = true;
}
//End
//If i remove the one upthere and just leave this one after the load it will replace all the items to 0 and they will appear unchecked
if (CheckChangeNow.Checked == true)
{
CheckChangeNow.SubItems[0].Text = "1";
}
else
{
CheckChangeNow.SubItems[0].Text = "0";
CheckChangeNow.Checked = false;
}
}
}
Aucun commentaire:
Enregistrer un commentaire