Listbox Item "top" position
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 11 of 11

Thread: Listbox Item "top" position

Hybrid View

  1. #1
    Join Date
    Jul 2010
    Posts
    2

    Arrow Listbox Item "top" position

    How would i get it?
    I am trying to to make it easier for my program users to edit the list items. I want it to work like this:

    Code:
    Private sub list1_dblclick()
    text1.visible = true
    text1.text = list1.list(list1.listindex)
    'here is where i cannot figure out what to do(i know the below code wont work. i've tested it.)
    text1.top = list1.listindex.top
    end sub
    how could i get it that every time the user double clicks on a list item, that a textbox apears there all they have to do is edit the text and press enter.
    i mostly just need to get the "top" position of a selected list item.
    Last edited by HanneSThEGreaT; July 7th, 2010 at 09:45 AM.
    Share on Google+

  2. #2
    Join Date
    Jul 2001
    Location
    Sunny South Africa
    Posts
    11,098

    Re: Listbox Item "top" position

    Welcome to the forums!

    I'm afraid your'e on the wrong track. You have a great idea, but believe it or not, it may be very difficult to implement. Here is an example of how to go about with it :

    http://www.bigresource.com/Tracker/Track-vb-8cAR3xkIJJ/

    I personally would have used a ListView, as it already contains that capability
    Share on Google+

  3. #3
    Join Date
    Jul 2010
    Posts
    2

    Re: Listbox Item "top" position

    the capability of double clicking to edit the text?
    and yes i will try out the link. i will post on how it goes!
    Share on Google+

  4. #4
    Join Date
    Jul 2001
    Location
    Sunny South Africa
    Posts
    11,098

    Re: Listbox Item "top" position

    Quote Originally Posted by dageek247 View Post
    the capability of double clicking to edit the text?
    No. The concept of putting a textbox over an item, hence trying to make it editable.
    Share on Google+

  5. #5
    Join Date
    Jan 2006
    Location
    Chicago, IL
    Posts
    14,999

    Re: Listbox Item "top" position

    He wants the TOP index?

    If it can show all 6 rows, it scrolls. Otherwise, it goes to the TOP

    Code:
    Option Explicit
    
    Private Sub Command1_Click()
       Dim s%, x As Integer
       s = List1.TopIndex
       If s < List1.ListCount - 6 Then
         List1.TopIndex = List1.TopIndex + 5
       Else
         List1.TopIndex = 0
       End If
       For x = 0 To List1.ListCount - 1
        If List1.Selected(x) = True Then
          List1.Selected(x) = False
        End If
       Next x
    End Sub
    
    Private Sub Form_Load()
    Dim x%
    For x = 0 To 15
      List1.AddItem x + 1
    Next x
    End Sub
    David

    CodeGuru Article: Bound Controls are Evil-VB6
    2013 Samples: MS CODE Samples

    CodeGuru Reviewer
    2006 Dell CSP
    2006, 2007 & 2008 MVP Visual Basic
    If your question has been answered satisfactorily, and it has been helpful, then, please, Rate this Post!
    Share on Google+

  6. #6
    Join Date
    Jul 2001
    Location
    Sunny South Africa
    Posts
    11,098

    Re: Listbox Item "top" position

    Quote Originally Posted by dglienna View Post
    He wants the TOP index?
    I doubt, David. It seems as if the OP wants an editable listbox - therefore he / she needs to know each item's top position so that he / she can place a TextBox there.
    Share on Google+

  7. #7
    Join Date
    May 2010
    Posts
    12

    Re: Listbox Item "top" position

    Quote Originally Posted by dglienna View Post
    He wants the TOP index?

    If it can show all 6 rows, it scrolls. Otherwise, it goes to the TOP
    ...
    [/CODE]
    (First READ the Thread, then answer. *********.)

    BTT: You could compute the Position where to put the Textbox using TextHeight like this :
    Code:
    Private Sub List1_DblClick()
      Dim nPos As Long
      Dim nIndex As Long
      
      nPos = List1.TopIndex
      nIndex = List1.ListIndex
      
      Text1.Top = List1.Top + ((nIndex - nPos) * TextHeight("Ag"))
      
    End Sub
    Last edited by HanneSThEGreaT; July 8th, 2010 at 04:18 AM.
    Share on Google+

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  


Windows Mobile Development Center


Click Here to Expand Forum to Full Width

This is a CodeGuru survey question.


Featured


HTML5 Development Center