Results 1 to 3 of 3

Thread: MultiSelect listbox

  1. #1

    Thread Starter
    Hyperactive Member cajsoft's Avatar
    Join Date
    Aug 2000
    Location
    Glasgow, Scotland
    Posts
    295

    Question

    Hello again, I thought I'd strike again while the iron is hot!!

    Ok, I have 2 events (addfaultcause and deletefaultcause) - on_click

    I want to be able to multiselect the items in my listbox (lstfaultcause) and be able to delete the items from both the list box and my SQL table. At present I can delete only one selection at a time, but I'd like to be able to select multiple entries and delete them all at once.

    Can someone help? I need to be able to keep the index (shown in code below). I'm using RDO to connect

    ---Code Begins---

    Code:
    Private sub addfaultcause_click()
    Dim infault  As String
    
    infault = InputBox("Please enter the Fault Cause? ", "Enter Fault Cause", "")
    If infault = "" Then Exit Sub
    ans = MsgBox("Are you Sure? ", vbQuestion + vbYesNo, "Question")
    If ans = 6 Then
        cnCon.Connect = "uid=sa;pwd=;server=" & txtsvr & ";driver={SQL Server};database=" & txtdb & ";"
        cnCon.CursorDriver = rdUseOdbc
        cnCon.EstablishConnection  'rdDriverNoPrompt
        cnCon.AddCause infault
        cnCon.Close
        lstfaultcause.AddItem (infault)
    End Sub
    
    Private Sub deletefaultcause_click()
    Dim DelSet As rdoResultset
        cnCon.Connect = "uid=sa;pwd=;server=" & txtsvr & ";driver={SQL Server};database=" & txtdb & ";"
        cnCon.CursorDriver = rdUseOdbc
        cnCon.EstablishConnection  'rdDriverNoPrompt
        cnCon.DelCause lstfaultcause.ItemData(lstfaultcause.ListIndex)  'Delcause is SQL-Defined code
        Set DelSet = cnCon.LastQueryResults
        lstfaultcause.RemoveItem (lstfaultcause.ListIndex)
        cnCon.Close
    end sub
    I guess that I'd have to change the deletefaultcause_click event with need code to allow Multiselect in the list box.

    Thanks
    Craig.

  2. #2
    Fanatic Member
    Join Date
    Oct 1999
    Location
    England
    Posts
    982
    I have never used rdo and ODBC but maybe this will help. Have you tried traversing through the items in the list and if selected remove the item in the list and the subsequent record from the database.
    The following code will remove the highlighted rows from the listbox, it works from the last to the first this is because I use the listCount property.

    Code:
    Dim intLoop As Integer
        For intLoop = List1.ListCount - 1 To 0 Step -1
            If List1.Selected(intLoop) Then
                List1.RemoveItem (intLoop)
                'place the relevant record delete code here also
            End If
        Next


    Things I do when I am bored: DotNetable

  3. #3

    Thread Starter
    Hyperactive Member cajsoft's Avatar
    Join Date
    Aug 2000
    Location
    Glasgow, Scotland
    Posts
    295
    Thanks... That did the trick! I was nearly there with the code, as I tried something similar but never used the correct syntax.

    I'm a very new VB programmer as you can see...

    Thanks again,

    These forums are great!

    Craig.

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