ee020165
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.Ad d , , "Name", 4000
ListView1.ColumnHeaders.Ad d , , "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.Hei ght - 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
Text1.SetFocus
End Sub
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.Ad
ListView1.ColumnHeaders.Ad
'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.Hei
Text1.Top = ListView1.SelectedItem.Top
Text1.Left = ListView1.ColumnHeaders(2)
Text1.Visible = True 'Make textbox appear on listview
Text1.SetFocus
End Sub
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
example like:
'See 2nd column to 1st position
ListView1.ColumnHeaders(2)
ASKER
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
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
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
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 :^)
cheers :^)
Example:
Private Sub Form_Load()
ListView1.LabelEdit = lvwAutomatic
ListView1.View = lvwReport
ListView1.ColumnHeaders.Cl
ListView1.FullRowSelect = True
ListView1.ColumnHeaders.Ad
ListView1.ColumnHeaders.Ad
For i = 1 To 20
ListView1.ListItems.Add i, , ""
ListView1.ListItems(i).Sub
Next i
End Sub
Private Sub ListView1_AfterLabelEdit(C
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
ListView1.StartLabelEdit
End If
End Sub
Hope this helps and make sense to you.