3

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 Answers 3

3

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());
       }
  }
Sign up to request clarification or add additional context in comments.

1 Comment

SelectedIndices should be replaced by SelectedItems. Tried to suggest an edit, but the reviewer answered "This edit is incorrect". Go figure why.
1
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

4 Comments

i do use VS 2005. look ListItem properties no support here.
There is ListViewItem :). MSDN
Ok. Actually you didn't mentioned web or windows here, I thought you were asking about web (asp.net).
Tried to edit for typos, but got rejected when I renamed SelectedItmes to SelectedItems.
0
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;
    }

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.