Results 1 to 7 of 7

Thread: LstBoxes problem with lstIndex - causes click - event

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Aug 2000
    Location
    South Africa
    Posts
    113

    Angry

    Hi all,

    I have a list box where if I click on text in it the text gets removed from the list box.

    Now the problem is...

    The lstbox is filled with data that must be saved to a record. I use a for do loop..
    for i = 1 to lstBox-1 do
    lstBox.listIndex = i
    data1.recordset("stuff") = lstbox.text
    next i

    Now when the line lstbox.listindex is executed the computer somehow goes to my lstbox_Click sub. How do I stop it from throwing this click event while still setting the listindex to i. the problem is that when it goes to the click event the text is removed and then lstbox.text is empty.

    help anyone
    thanks in advance
    You are living a pacifist dream, and if you dreaming it means you sleeping and you should damn well wake up!

  2. #2
    _______ HeSaidJoe's Avatar
    Join Date
    Jun 1999
    Location
    Canada
    Posts
    3,946

    <?>

    for delete I would use DblClick event.
    "A myth is not the succession of individual images,
    but an integerated meaningful entity,
    reflecting a distinct aspect of the real world."

    ___ Adolf Jensen

  3. #3
    Fanatic Member
    Join Date
    Jan 2000
    Location
    Nitro
    Posts
    633
    If you creating the program for yourself, I would go with HeSaidJoe. If you are creating it for end users, I would all a command button because end users might not know about the double click. It is better to have something visual for them.
    Chemically Formulated As:
    Dr. Nitro

  4. #4
    _______ HeSaidJoe's Avatar
    Join Date
    Jun 1999
    Location
    Canada
    Posts
    3,946

    <?>

    Code:
    Option Explicit
    
    Private Sub Command1_Click()
        Open "C:\my documents\mytext.txt" For Output As #1
        Dim i As Integer
        For i = 0 To lstbox.ListCount - 1
        lstbox.ListIndex = i
        Print #1, lstbox.Text
        Next
    End Sub
    
    Private Sub Form_Load()
        Dim i
        For i = 1 To 10
        
        lstbox.AddItem i
        Next i
    End Sub
    
    Private Sub lstbox_DblClick()
     lstbox.RemoveItem (lstbox.ListIndex)
    End Sub
    "A myth is not the succession of individual images,
    but an integerated meaningful entity,
    reflecting a distinct aspect of the real world."

    ___ Adolf Jensen

  5. #5
    Fanatic Member
    Join Date
    Aug 2000
    Posts
    736
    I had a similar problem with a DataGrid control and the RowColChange event. I ended up setting a flag before executing the loop. The click event would still be called, but would execute only when the flag was set.

    Set up a boolean variable such as:
    Global blnContinue as Boolean

    And set it so it will be true:
    blnContinue = True

    And in your loop do this.

    [code]
    blnContinue=False
    for i = 1 to lstBox-1 do
    lstBox.listIndex = i
    data1.recordset("stuff") = lstbox.text
    next i
    blnContinue=True

    and in your click event:

    [code]
    Private Sub lstbox_click()
    If blnContinue=False then exit sub
    ....
    ....
    End Sub

    Might not be the greatest solution, but it worked for me.

    Good luck !

    [Edited by jbart on 09-13-2000 at 02:24 PM]

  6. #6
    New Member
    Join Date
    Dec 2000
    Location
    Carlisle, PA
    Posts
    5

    Unhappy

    I can't answer it but would like toask a question.
    I have two list boxes whcih are the following.
    lstChoices and lstNames.
    lstChoices has items like
    Full-Time
    Full-Time/New Cars
    Full-Time/Used Cars
    New Cars
    Part-Time
    Part-Time/New Cars ; etc. these are loaded from form load
    The lstNames list box has nothing in it. I am supposed to code the lstChoices control's click event so that it displays the appropriate listing of Names in the lstNames list box. The Names are in a .dat file on a disk on the a: drive. The book says . Hint: use the Instr function. The hint dosen't help me ; can you?
    Thank You,
    Mark


  7. #7
    Addicted Member c@lle's Avatar
    Join Date
    Oct 1999
    Location
    Belgium
    Posts
    179
    I never use a loop like above.
    You are all selecting the item by setting the listindex of the listbox.

    I use the following (so you don't generate a click event at all)

    Code:
        For intIndex = 0 To (lstBox.ListCount - 1)
            strKey = lstBox.List(intIndex)
        Next
    With the for loop you run through the listbox, with the lstBox.List(intIndex) you select the text in the listbox.

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