Results 1 to 3 of 3

Thread: Getting the value of the select items in listbox...should be easy...

  1. #1

    Thread Starter
    PowerPoster hellswraith's Avatar
    Join Date
    Jul 2002
    Location
    Washington St.
    Posts
    2,464

    Getting the value of the select items in listbox...should be easy...

    Hey all.

    I am brain dumping right now, and can't figure this out...
    I have a list box that was databound to a table in the form load
    (Private dtTeam As DataTable)

    Now, I need to loop through the selected items, and add the ValueMember field (NOT the text) of the selected item to another datatable.

    Here is what I have came up with...but I don't know how to get the value member.
    VB Code:
    1. If lbxTeam.SelectedItems.Count > 0 Then
    2.             For i As Integer = 0 To lbxTeam.SelectedItems.Count - 1
    3.                 drRow = dsData.Tables("Teams").NewRow()
    4.                 drRow("EntityID") = lbxTeam.SelectedItems.Item(i) '?????????????????
    5.                 dsData.Tables("Teams").Rows.Add(drRow)
    6.             Next
    7.         End If

    This should be super simple, but I have been asp.net developing for a long while, and don't remember.

  2. #2
    Your Ad Here! Edneeis's Avatar
    Join Date
    Feb 2000
    Location
    Moreno Valley, CA (SoCal)
    Posts
    7,339
    Try:
    VB Code:
    1. For i As Integer = 0 To lbxTeam.SelectedItems.Count - 1
    2.                 drRow = dsData.Tables("Teams").NewRow()
    3.                 drRow("EntityID") = CType(lbxTeam.SelectedItems.Item(i), DataRowView).Item(lbxTeam.ValueMember))
    4.                 dsData.Tables("Teams").Rows.Add(drRow)
    5.             Next

  3. #3

    Thread Starter
    PowerPoster hellswraith's Avatar
    Join Date
    Jul 2002
    Location
    Washington St.
    Posts
    2,464
    Thanks, that was exactly what I needed. Just have to cast it to a dataview....huh..., I don't think I would have headed down that path anytime soon. I understand why now, but I wouldn't have led myself that way...lol.

    Thanks again.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width