hi! i have a listbox binded to a list. the list contains checkboxes binded to a field/member of the list. what i want to achieve is that i want to delete the data from list when it's corresponding checkbox is checked...

here's my xaml code:

<ListBox Name="ListBox1" ItemsSource="{Binding histList, Mode=OneWay}" Margin="10,10,10,10" Height="197" VerticalAlignment="Center" >
    <ListBox.ItemTemplate>
        <DataTemplate>
            <CheckBox Content="{Binding FilterName, Mode=TwoWay}" />
        </DataTemplate>
    </ListBox.ItemTemplate>
</ListBox>

here's the code in the .cs file

namespace ReportsUIScreens
{
    public partial class EditStyle : ChildWindow
    {
        private List<filterHistory> histList;
        public EditStyle(List<filterHistory> histListLink)
        {
            InitializeComponent();
            histList = histListLink;
            this.ListBox1.ItemsSource=histList;
        }
 
        private void OKButton_Click(object sender, RoutedEventArgs e)
        {
            //HERE'S WHERE I WANT TO DELETE
            this.DialogResult = true;
        }
        .........
        .........
        .........
    }
}

please help me...

Hi,
one thing: a "list" as you have stated - it canNOT have checkBoxes at all. It can only contain some boolean values.

So, in your code you have a generic list<T> with a custom class "filterHistory". This is a class which has a boolan property - for the checkBox checked/uncheced if I`m not wrong.

I hope I`m not wrong - but this is only my presuming, regarding your code, so we can do the following: lets loop through the list, and check for that boolean property - if value is true - delete the data (if false, do notihing; dont delete the data):

for(filterHistory item in histList)
{
     if(item.checkUncheck)
     {
         //here item is true! so you can delete the data!!
     }
}

//your filterHistory class //this is only my predistion how it looks:
class filterHistory
{
     public bool checkUncheck { get; set; }
     //and the rest
}
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.