Link to home
Create AccountLog in
Avatar of ee020165
ee020165Flag for Malaysia

asked on

How to make textbox scroll with listview (or make it just disappear when listview scrolled)

One listview and one textbox is created in vb6.
The code below will make the textbox appear on the listview at the row clicked so that marks can entered.
The problem is when we scroll the listview the textbox does'nt scroll together with it'
Is it possible to let the textbox scroll with it, or if not possible how can we make the textbox invisible
when the listview is scrolled. That is, is there something like a SCROLL event for the listview?

Private Sub Form_Activate()
Dim itmx As ListItem
ListView1.ColumnHeaders.Add , , "Name", 4000
ListView1.ColumnHeaders.Add , , "Marks", 1000
'First row added
Set itmx = ListView1.ListItems.Add(, , "Patrick")
itmx.SubItems(1) = "80"
'Second row added
Set itmx = ListView1.ListItems.Add(, , "James")
itmx.SubItems(1) = "75"
'More rows added until listview will show scroll bar
End Sub

Private Sub ListView1_Click()
Text1.Height = ListView1.SelectedItem.Height - 10   'Adjust height of textbox to fit row of listview
Text1.Top = ListView1.SelectedItem.Top + ListView1.Top + 50   'Position top of textbox
Text1.Left = ListView1.ColumnHeaders(2).Left + 450   'Position left of textbox
Text1.Visible = True   'Make textbox appear on listview
End Sub
Avatar of Ryan Chong
Ryan Chong
Flag of Singapore image

How many columns' value you want to modify? You can try use the LabelEdit feature in listview to edit one of the column's value in listview.


Private Sub Form_Load()
    ListView1.LabelEdit = lvwAutomatic
    ListView1.View = lvwReport
    ListView1.FullRowSelect = True
    ListView1.ColumnHeaders.Add , , "Marks"
    ListView1.ColumnHeaders.Add , , "My Items"
    For i = 1 To 20
        ListView1.ListItems.Add i, , ""
        ListView1.ListItems(i).SubItems(1) = "Item " & i
    Next i
End Sub

Private Sub ListView1_AfterLabelEdit(Cancel As Integer, NewString As String)
    If (IsNumeric(NewString) = False) Then
        Cancel = True
        Exit Sub
    End If
    If Int(NewString) > 100 Or Int(NewString) < 0 Then
        Cancel = True
        Exit Sub
    End If
End Sub

Private Sub ListView1_MouseUp(Button As Integer, Shift As Integer, x As Single, y As Single)
    If Button = 1 Then
    End If
End Sub

Hope this helps and make sense to you.
Add this in Form_Load event if you want to reorder the listview columns

example like:

'See 2nd column to 1st position
ListView1.ColumnHeaders(2).Position = 1
Avatar of ee020165


I would sure put this as an assisted solution later. It seem as a good way around but I need to do a lot of recoding because I have about 20 columns for 20 subjects to cater with. I would prefer to minimize my recoding
Avatar of Ryan Chong
Ryan Chong
Flag of Singapore image

Link to home
Create an account to see this answer
Signing up is free. No credit card required.
Create Account
Wow that's sofiscticated coding. I never really understand api programming. Anyway I think I solved the problem in a way by putting some codes in the listview mouse move event which will take effect when we move the mouse away from the scroll bar to the names we want in the listview

ryancys, if you don't have addtional comments, I will accept one of  your contributions as the accepted solution. thanks
Hmmm, first, glad that you find out a solution, second, you can post your solution here if you wish to share with others.

cheers :^)