locked
Reloading Multiselect Listbox controls RRS feed

  • Question

  • I have a multiselect list box on a Windows form (VS 2008) containing references to 35 different work stations.  The end user can select any number of workstations in this listbox, then store those selections to a SQL table (this part is working fine).  The problem is getting those same workstations highlighted/selected when the user recalls that record from the database, in the event that there are addtions or changes.  Here is the relevant code for the reload:

          If lstChange.CurrentRow.Cells(6).Value <> "" Then
            Dim strTemp As String = lstChange.CurrentRow.Cells(6).Value
            For Each drv As DataRowView In lstWkStns.Items
              If strTemp.Contains(drv(0) & "|") = True Then<br/>		  <strong>(THIS IS WHERE THE RELOAD CODE WOULD GO?)</strong>
              End If
            Next
          End If
    
    All the existing references are displayed in a DataGridView (identified as lstChange).  The currently-selected work stations are contained in column 6 of the DataGridView, and if there is anything there, I want to application to flag all those workstations in the listbox.  I'm sure it is something brain-dead simple that I am just missing, or perhaps I am making this more complicated than necessary, but either way I am stumped on how to accomplish this seemingly simple task.  Any help or guidance would be greatly appreciated!
    LDC
    Monday, October 4, 2010 5:15 PM

Answers

  • As I suspected, the solution was simple an obvious.  Just parse the string into an array, then use the array to select the matching values in the listbox.
    LDC
    • Marked as answer by LyleD Tuesday, October 12, 2010 5:08 PM
    Tuesday, October 12, 2010 5:07 PM

All replies

  • Hello LyleD,

    Thanks for your post.

    I am sorry I could not understand your problem very clearly. If the currently-selected workstation is contained in the column6 of the DataGridView, what do you mean "flag all those workstations in the listbox"? Could you please describe your problem more specific?

    If strTemp.Contains(drv(0) & "|") = True Then

    Do you want to know how to code this part? What do you want to implement?

    End If

    Best regards,
    Liliane
    MSDN Subscriber Support in Forum
    If you have any feedback on our support, please contact msdnmg@microsoft.com


    Please mark the replies as answers if they help and unmark them if they provide no help. Welcome to the All-In-One Code Framework! If you have any feedback, please tell us. Thanks
    Wednesday, October 6, 2010 3:50 AM
  • As I suspected, the solution was simple an obvious.  Just parse the string into an array, then use the array to select the matching values in the listbox.
    LDC
    • Marked as answer by LyleD Tuesday, October 12, 2010 5:08 PM
    Tuesday, October 12, 2010 5:07 PM