Reputation: 157
I'm having another issue here. I have a class and a List for my Purchasers:
public class Purchaser
{
public string Name { get; set; }
public bool Paid { get; set; }
}
List<Purchaser> Purchasers = new List<Purchaser>();
I also have a code to add new purchasers by cathing the text from one textbox and adding it to the Purchaser List and to my listbox listDOF:
if(box_AddPerson.TextLength != 0)
{
Purchaser purchaser = new Purchaser();
purchaser.Name = caixa_AddJog.Text;
purchaser.Paid = true;
listDOF.Items.Add(purchaser.Name);
Purchasers.Add(purchaser);
}
Ok, now I want be able to assign the variable Paid for each purchaser using a checkbox, but I really do not know how to do this. I've searched but found nothing.
According to the selected purchaser in the listbox, I want be able to change his variable, by checking or unchecking the checkbox. I tried this:
private void box_Paid_CheckedChanged(object sender, EventArgs e)
{
if (box_Paid.Checked == true)
{
Purchaser p = new Purchaser(listDOF.SelectedIndex);
p.Paid = true;
}
}
But this is not working. Can anyone give me a hand? Thanks all in advance!
Upvotes: 0
Views: 37
Reputation: 2103
You could use this instead:
private void box_Paid_CheckedChanged(object sender, EventArgs e)
{
if (box_Paid.Checked == true)
{
Purchaser p = Purchasers[listDOF.SelectedIndex];
p.Paid = true;
}
}
Upvotes: 1