ListBox On Click Event

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • buddydasari
    New Member
    • Mar 2007
    • 14

    ListBox On Click Event

    Hi all

    I wrote a listbox onclick event.On a click i want to get the selected row details but the listbox.selecte d(i) always returns false ,it returns true only in
    double click event.Are they any other events on which i could do this.I want to populate a textbox based on the row selected from the listbox.Its working as i want when i add the code in a double click event but it doesn't make much sense doing it on a double click event.

    thanks
    Sree
  • missinglinq
    Recognized Expert Specialist
    • Nov 2006
    • 3533

    #2
    The standard method for doing this sort of thing uses the AfterUpdate event of the listbox (or combobox) not the Click or DoubleClick event.

    Welcome to Bytes!

    Linq ;0)>

    Comment

    • buddydasari
      New Member
      • Mar 2007
      • 14

      #3
      missinglinq

      I tried that too.Didn't work either.the listbox.selecte d returns false in any event except in double click evnt.

      thanks
      Sree

      Comment

      • missinglinq
        Recognized Expert Specialist
        • Nov 2006
        • 3533

        #4
        This type of thing is normally done without using the Selected property at all, something like this.

        Code:
        Private Sub YourListBoxName_AfterUpdate()
             Me.TextBox1 = Me.YourListBoxName.Column(0)
             Me.TextBox2 = Me.YourListBoxName.Column(1)
             Me.TextBox3 = Me.YourListBoxName.Column(2)
        End Sub
        Note that the columns are Zero-based, so the first column (reading left-to-right) would be column(0), the second column(1) and so forth.

        When you click on a row to select it the textboxes are filled in.

        Linq ;0)>

        Comment

        • buddydasari
          New Member
          • Mar 2007
          • 14

          #5
          All

          Got it worked using listbox.listInd ex property instead of listbox.Selecte d property on OnClick event


          thanks for ur help
          Sree

          Comment

          • missinglinq
            Recognized Expert Specialist
            • Nov 2006
            • 3533

            #6
            Glad you got it working. The Selected Property is intended to be used when the Listbox Multi-Select Property is set to either Simple or Extended. You use it to loop thru all rows to see which are selected. It's really not meant to be used in your type of application.


            Linq ;0)>

            Comment

            Working...