?
Solved

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

Posted on 2007-10-06
6
Medium Priority
?
878 Views
Last Modified: 2013-12-26
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
Text1.SetFocus
End Sub
0
Comment
Question by:ee020165
  • 4
  • 2
6 Comments
 
LVL 54

Expert Comment

by:Ryan Chong
ID: 20028941
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.

Example:

Private Sub Form_Load()
    ListView1.LabelEdit = lvwAutomatic
    ListView1.View = lvwReport
    ListView1.ColumnHeaders.Clear
    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
        ListView1.StartLabelEdit
    End If
End Sub


Hope this helps and make sense to you.
0
 
LVL 54

Expert Comment

by:Ryan Chong
ID: 20028950
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
0
 

Author Comment

by:ee020165
ID: 20029653
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
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 54

Accepted Solution

by:
Ryan Chong earned 2000 total points
ID: 20030015
try something like this:

in your form:

Private Declare Function SetWindowLong Lib "user32" Alias "SetWindowLongA" (ByVal hWnd As Long, ByVal nIndex As Long, ByVal dwNewLong As Long) As Long

Private Sub Form_Load()
    ListView1.LabelEdit = lvwAutomatic
    ListView1.View = lvwReport
    ListView1.ColumnHeaders.Clear
    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
    ListView1.ColumnHeaders(2).Position = 1
   
    PrevProc = SetWindowLong(ListView1.hWnd, GWL_WNDPROC, AddressOf WindowProc)
End Sub

Private Sub Form_Unload(Cancel As Integer)
    SetWindowLong ListView1.hWnd, GWL_WNDPROC, PrevProc
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
        ListView1.StartLabelEdit
    End If
End Sub

in a module:

Public Const GWL_WNDPROC = (-4)
Private Const WM_VSCROLL = &H115
Private Declare Function CallWindowProc Lib "user32" Alias "CallWindowProcA" (ByVal lpPrevWndFunc As Long, ByVal hWnd As Long, ByVal Msg As Long, ByVal wParam As Long, ByVal lParam As Long) As Long

Public PrevProc As Long

Public Function WindowProc(ByVal hWnd As Long, ByVal uMsg As Long, ByVal wParam As Long, ByVal lParam As Long) As Long
    If uMsg = WM_VSCROLL Then
        If hWnd = Form1.ListView1.hWnd Then
            'put your scripts here to hide your controls here
            Debug.Print "ListView is scrolled : " & Now
        End If
    End If
    'Processing = False
    WindowProc = CallWindowProc(PrevProc, hWnd, uMsg, wParam, lParam)
   
End Function


try customize according.

hope this helps
0
 

Author Comment

by:ee020165
ID: 20032219
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
0
 
LVL 54

Expert Comment

by:Ryan Chong
ID: 20032241
Hmmm, first, glad that you find out a solution, second, you can post your solution here if you wish to share with others.

cheers :^)
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Although it can be difficult to imagine, someday your child will have a career of his or her own. He or she will likely start a family, buy a home and start having their own children. So, while being a kid is still extremely important, it’s also …
What do responsible coders do? They don't take detrimental shortcuts. They do take reasonable security precautions, create important automation, implement sufficient logging, fix things they break, and care about users.
Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …
Progress

850 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question