checkedlist box uncheck remove items

51 views Asked by At

I've 2 checklistboxes. 1st checklist box is sublist and 2nd checklist box is brandlist. There are multiple items in sublist checklistbox. Once checked it will fill in brandlist checkbox. But the problem is if I uncheck also, it is filled again in brandlist checkbox.

The following code fills in brandlist checkbox. How to remove the items when unchecked? I am very new to dotnet.

private void chklstSubList_SelectedIndexChanged(object sender, EventArgs e)
{
  string Sub = chklstSubList.SelectedItem.ToString();
  Fill_Brands(Convert.ToInt32(Sub));
}

this is the Fill_Brands function

private void Fill_Brands(int Sub) 
{ 

    DataTable sourceTable = new DataTable(); 
    sourceTable = ppfcObj.GetBrandMasterListFromRMS(Sub); 

    for (int i = 0; i < sourceTable.Rows.Count; i++) 
    { 
        string Brand = Sub.ToString() + "-" + 
                       sourceTable.Rows[i][0].ToString().Trim() + "-" +
                       sourceTable.Rows[i][1].ToString().Trim();
        chklstMstrBrandList.Items.Add(Brand); 
    } 
}
0

There are 0 answers