Please help - One technical question on ListBox...

Discussion in 'MCSD' started by Vincent, Feb 11, 2004.

  1. Vincent

    Vincent Guest

    Dear Experts,

    I got one technical question on using ListBox. I don't
    know how to solve it, please help.

    Scenario:
    I placed a ListBox on the Form and I would like to allow
    my users to do multiple selection. After users select the
    item(s), I want to collect all the
    corresponding "SelectValue"(s)(SelectedValue is a
    property of the ListBox, as you know).

    However, no matter how hard I tried, I was unable to
    iterate through all the selected items and found out
    the "SelectedValue"(s). Could you please tell me how to
    code?

    The setting of the ListBox is the following:
    Selection Mode: Multiple Extended
    DataSouce: Dataset1.Customers (I am using ADO.NET)
    DisplayMember: CustomerName
    ValueMember: CustomerID (it is the source
    of "SelectedValue")

    Thanks a lot for your help.
    Vincent
     
    Vincent, Feb 11, 2004
    #1
    1. Advertisements

  2. foreach(DataRowView dv in this.listBox1.SelectedItems)
    {
    DataSet1.CustomersRow dr = (DataSet1.CustomersRow)dv.Row;
    Debug.WriteLine(dr.ContactName + ", " + dr.CustomerID, "name + id");
    }


    or

    foreach(int i in this.listBox1.SelectedIndices)
    {
    DataSet1.CustomersRow dr =
    (DataSet1.CustomersRow)this.dataSet11.Customers.Rows;
    Debug.WriteLine(dr.ContactName + ", " + dr.CustomerID, "name + id");
    }

    --caspy
     
    news.microsoft.com, Feb 11, 2004
    #2
    1. Advertisements

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.