2
votes

I have two ListBoxes. First ListBox items are list of "Products". and second ListBox items are list of "Item in Product" so When user click the item in first(Product) Listbox The second ListBox will show the list of items in selected Products.

eg:

Products     Items in Proucts
  AA*                 1
  BB                  2
  CC                  3   

in example above current user selected AA products. And 1,2,3 are the items in product AA.

For the current program,i've done. User only can select One "Products" at a time. Then i want to change to multipleselected. So i want to get index number for each product that user selects, then i can retrieve data from database to get "Items In Products" for all selected products.

if (productsListBox.SelectedItmes.Count >= 0)
{
 // please provide me coding here to get index number for each selected items in   productListBox.
}
3

3 Answers

3
votes

i already getting the answer:

 if (productListBox.SelectedItems.Count >= 0)
 {
    for (int i = 0; i < productListBox.SelectedItems.Count; i++)
       {
            MessageBox.Show(productListBox.SelectedIndices[i].ToString());
       }
  }
1
votes
if (productsListBox.SelectedItmes.Count >= 0)
{

    string IDs = string.Empty;
    foreach( ListItem li in productsListBox.SelectedItmes ) 
    {
        IDs += li.Value+"," ;
    }
        IDs = IDs.Trim(',');

}

It'll give you a CSV of selected IDs

0
votes
private string GetTagsList()
    {
        string Tags = string.Empty;

        if (lstTags.SelectedItems.Count >= 0)
        {
            for (int i = 0; i < lstTags.SelectedItems.Count; i++)
            {
                Tags += lstTags.SelectedIndices[i].ToString() + ",";
            }
            Tags = Tags.Trim(',');
        }

        return Tags;
    }