Results 1 to 7 of 7

Thread: get value from listview

  1. #1

    Thread Starter
    PowerPoster
    Join Date
    Mar 2005
    Posts
    2,586

    get value from listview

    I know only to get the row with:

    Code:
    Private Sub CALENDAR_Click()
    
        Dim L As Long
        L = Empty
        L = Me.CALENDAR.SelectedItem.Index
    
    End Sub
    But how to get the value in clicked cell on listview?
    similar a Naval Battle X,Y coordinate
    in effect i need the number of index of related column

  2. #2
    Junior Member
    Join Date
    May 2020
    Posts
    18

    Re: get value from listview

    Hi, have you tried the "ItemClick" (ByVal Item As MSComctlLib.ListItem)?
    best regards
    Federico

  3. #3

    Thread Starter
    PowerPoster
    Join Date
    Mar 2005
    Posts
    2,586

    Re: get value from listview

    Quote Originally Posted by federico07 View Post
    Hi, have you tried the "ItemClick" (ByVal Item As MSComctlLib.ListItem)?
    best regards
    Federico
    YES! ItemClick event

  4. #4
    Junior Member
    Join Date
    May 2020
    Posts
    18

    Re: get value from listview

    you can try this function
    'call it
    array=GetRowColumn(Item, listbiew)
    this is the function to get the column clicked

    Public Declare Function GetScrollPos Lib "user32" _
    (ByVal hwnd As Long, ByVal nBar As Long) As Long

    Public Const SB_HORZ = 0
    Public lvX As Long

    Public Function GetRowColumn(ByVal Item As MSComctlLib.ListItem, ByRef Lv As ListView) As Long()
    Dim ColH As ColumnHeader
    Dim pix As Long
    Dim Index As Long
    Dim ret(0 To 1) As Long
    Dim XVal As Long

    'Use the API to get the scroll bar's pixel position
    XVal = (GetScrollPos(Lv.hwnd, SB_HORZ) * _
    Screen.TwipsPerPixelX) + lvX

    'Traverse each column until the X coordinate we clicked on
    'becomes less then the total of the traversed columns'
    'widths.
    For Each ColH In Lv.ColumnHeaders
    pix = pix + ColH.Width
    If (pix >= XVal) Then Exit For
    Index = Index + 1
    Next

    'returnrow and column in a 2D array
    ret(0) = Item.Index - 1
    ret(1) = Index
    GetRowColumn = ret
    End Function

    Hope this code helps you
    Last edited by federico07; Jun 1st, 2020 at 12:00 PM.

  5. #5

    Thread Starter
    PowerPoster
    Join Date
    Mar 2005
    Posts
    2,586

    Re: get value from listview

    Quote Originally Posted by federico07 View Post
    you can try this function
    'call it
    array=GetRowColumn(Item, listbiew)
    this is the function to get the column clicked

    Public Declare Function GetScrollPos Lib "user32" _
    (ByVal hwnd As Long, ByVal nBar As Long) As Long

    Public Const SB_HORZ = 0
    Public lvX As Long

    Public Function GetRowColumn(ByVal Item As MSComctlLib.ListItem, ByRef Lv As ListView) As Long()
    Dim ColH As ColumnHeader
    Dim pix As Long
    Dim Index As Long
    Dim ret(0 To 1) As Long
    Dim XVal As Long

    'Use the API to get the scroll bar's pixel position
    XVal = (GetScrollPos(Lv.hwnd, SB_HORZ) * _
    Screen.TwipsPerPixelX) + lvX

    'Traverse each column until the X coordinate we clicked on
    'becomes less then the total of the traversed columns'
    'widths.
    For Each ColH In Lv.ColumnHeaders
    pix = pix + ColH.Width
    If (pix >= XVal) Then Exit For
    Index = Index + 1
    Next

    'returnrow and column in a 2D array
    ret(0) = Item.Index - 1
    ret(1) = Index
    GetRowColumn = ret
    End Function

    Hope this code helps you
    tks!

    note:
    ma sei italiano?

  6. #6
    Junior Member
    Join Date
    May 2020
    Posts
    18

    Re: get value from listview

    no, argentino

  7. #7

    Thread Starter
    PowerPoster
    Join Date
    Mar 2005
    Posts
    2,586

    Re: get value from listview

    Quote Originally Posted by federico07 View Post
    no, argentino
    NICE!

    Similar a Napolitan! (Maradona docet!)

    I'm Napolitan:-)

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