Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Updating Listbox Selected Values 1

Status
Not open for further replies.

OrWolf

MIS
Mar 19, 2001
291
0
0
I've tried searching for this one and I'm not finding the answer I'm looking for. I have a form that has a list box that shows employees. I need to know how to allow a user to select multiple employees in that list and save them in a related table as independant records.

For example the form is based on table Demo. When employees are selected for Demo 'ABC' they are written to the DemoEmployees table with a foreign key of 'ABC' so the next time the form is opened those same employees are selected in the listbox.

Does anyone have any good examples of this in action?
 
Code:
Dim table As DataTable
With Me.YourListBoxName
    'table = CType(.DataSource, DataTable)
    table = CType(.DataSource, DataView).Table
End With

' Process in reverse order because we are deleting rows.
For index As Integer = table.Rows.Count - 1 To 0 Step -1
    If Not Me.YourListBoxName.SelectedIndices.Contains(index) Then
        ' Current row is not selected so delete it.
        ' Rows are not actually deleted, but their RowState is marked deleted.
        table.Rows(index).Delete
    End If
    index -= 1
Next
 
Big Goof, Do NOT use this line
Code:
index -= 1
Sorry, had a major brain cramp!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top