Results 1 to 38 of 38

Thread: I can' find a title to this issue!!!

  1. #1

    Thread Starter
    Fanatic Member
    Join Date
    Oct 2013
    Posts
    783

    I can' find a title to this issue!!!

    Hello vbforums
    I hesitate for a long time before I wrote about my worry. I can't even find a title to describe the issue. because I thought it is impossible.
    But my last experience learnt me that everything is possible on Vbforums.

    I'am copying data from a listview to a multiline textbox.
    Code:
    Private Sub lvw_ItemClick(ByVal Item As MSComctlLib.ListItem)
    
    clicknum = clicknum + 1
     Select Case clicknum
    
         Case 1
      Text1.Text = "  " & "1-" & " " & lvw.SelectedItem.Text & String$(50, " ") & _
    lvw.SelectedItem.ListSubItems(1).Text & vbNewLine & String$(50, " ") & _
     lvw.SelectedItem.ListSubItems(2).Text
    
        Case 2
     Text1.Text = Text1.Text & vbNewLine & vbNewLine & "  " & "2-" & " " & _
     lvw.SelectedItem.Text & String$(50, " ") & _
    lvw.SelectedItem.ListSubItems(1).Text & vbNewLine & String$(50, " ") & _
     lvw.SelectedItem.ListSubItems(2).Text
      Case 3
     Text1.Text = Text1.Text & vbNewLine & vbNewLine & "  " & "3-" & " " & _
     lvw.SelectedItem.Text & String$(50, " ") & _
    lvw.SelectedItem.ListSubItems(1).Text & vbNewLine & String$(50, " ") & _
     lvw.SelectedItem.ListSubItems(2).Text
                               
      Case 4
     Text1.Text = Text1.Text & vbNewLine & vbNewLine & "  " & "4-" & " " & _
     lvw.SelectedItem.Text & String$(50, " ") & _
    lvw.SelectedItem.ListSubItems(1).Text & vbNewLine & String$(50, " ") & _
     lvw.SelectedItem.ListSubItems(2).Text
                               
         Case 5
     Text1.Text = Text1.Text & vbNewLine & vbNewLine & "  " & "5-" & " " & _
     lvw.SelectedItem.Text & String$(50, " ") & _
    lvw.SelectedItem.ListSubItems(1).Text & vbNewLine & String$(50, " ") & _
     lvw.SelectedItem.ListSubItems(2).Text                   
      End Select
    End Sub
    This is the output:
    Name:  line.png
Views: 310
Size:  8.0 KB

    What I need is to put the lvw.SelectedItem.ListSubItems(1).Text in the same vertical line. I mean they should have the same"left" regardless the length of the lvw.SelectedItem.Text.
    I thought of using: If Len(lvw.SelectedItem.ListSubItems(1). = ?? then String$(??, " ") but this is not pratical at all.
    Thanks

  2. #2
    VB-aholic & Lovin' It LaVolpe's Avatar
    Join Date
    Oct 2007
    Location
    Beside Waldo
    Posts
    19,541

    Re: I can' find a title to this issue!!!

    Instead of using spaces try using tabs. The tab positions of a textbox can be set with APIs. Or, just use a fixed-pitch/mono-space font where each character's width uses exactly the same number of pixels.
    Insomnia is just a byproduct of, "It can't be done"

    Classics Enthusiast? Here's my 1969 Mustang Mach I Fastback. Her sister '67 Coupe has been adopted

    Newbie? Novice? Bored? Spend a few minutes browsing the FAQ section of the forum.
    Read the HitchHiker's Guide to Getting Help on the Forums.
    Here is the list of TAGs you can use to format your posts
    Here are VB6 Help Files online


    {Alpha Image Control} {Memory Leak FAQ} {Unicode Open/Save Dialog} {Resource Image Viewer/Extractor}
    {VB and DPI Tutorial} {Manifest Creator} {UserControl Button Template} {stdPicture Render Usage}

  3. #3

    Thread Starter
    Fanatic Member
    Join Date
    Oct 2013
    Posts
    783

    Re: I can' find a title to this issue!!!

    Thank you sir
    But what you are suggesting is out of my capacities.

  4. #4
    VB-aholic & Lovin' It LaVolpe's Avatar
    Join Date
    Oct 2007
    Location
    Beside Waldo
    Posts
    19,541

    Re: I can' find a title to this issue!!!

    Nah, for examples, just give the forum a quick search for: em_settabstops
    Insomnia is just a byproduct of, "It can't be done"

    Classics Enthusiast? Here's my 1969 Mustang Mach I Fastback. Her sister '67 Coupe has been adopted

    Newbie? Novice? Bored? Spend a few minutes browsing the FAQ section of the forum.
    Read the HitchHiker's Guide to Getting Help on the Forums.
    Here is the list of TAGs you can use to format your posts
    Here are VB6 Help Files online


    {Alpha Image Control} {Memory Leak FAQ} {Unicode Open/Save Dialog} {Resource Image Viewer/Extractor}
    {VB and DPI Tutorial} {Manifest Creator} {UserControl Button Template} {stdPicture Render Usage}

  5. #5
    PowerPoster
    Join Date
    Sep 2006
    Location
    Egypt
    Posts
    2,579

    Re: I can' find a title to this issue!!!

    Here is a solution implements LaVolpe's suggestion

    In Form declaration section add
    Code:
    Const EM_SETTABSTOPS = &HCB
    Private Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, lParam As Any) As Long
    In Form_Load event add
    Code:
        Dim lngTabStop(1) As Long
        lngTabStop(0) = 200
        lngTabStop(1) = 230
        SendMessage Text1.hwnd, EM_SETTABSTOPS, 2, lngTabStop(0)
    Replace your lvw_ItemClick with the following one
    Code:
    Private Sub lvw_ItemClick(ByVal Item As MSComctlLib.ListItem)
        clicknum = clicknum + 1
        Select Case clicknum
            Case 1
                Text1.Text = "  1- " & lvw.SelectedItem.Text & vbTab & vbTab & _
                lvw.SelectedItem.ListSubItems(1).Text & vbNewLine & vbTab & _
                lvw.SelectedItem.ListSubItems(2).Text
            Case 2
                Text1.Text = Text1.Text & vbNewLine & vbNewLine & "  2- " & _
                lvw.SelectedItem.Text & vbTab & vbTab & _
                lvw.SelectedItem.ListSubItems(1).Text & vbNewLine & vbTab & _
                lvw.SelectedItem.ListSubItems(2).Text
            Case 3
                Text1.Text = Text1.Text & vbNewLine & vbNewLine & "  3- " & _
                lvw.SelectedItem.Text & vbTab & vbTab & _
                lvw.SelectedItem.ListSubItems(1).Text & vbNewLine & vbTab & _
                lvw.SelectedItem.ListSubItems(2).Text
            Case 4
                Text1.Text = Text1.Text & vbNewLine & vbNewLine & "  4- " & _
                lvw.SelectedItem.Text & vbTab & vbTab & _
                lvw.SelectedItem.ListSubItems(1).Text & vbNewLine & vbTab & _
                lvw.SelectedItem.ListSubItems(2).Text
            Case 5
                Text1.Text = Text1.Text & vbNewLine & vbNewLine & "  5- " & _
                lvw.SelectedItem.Text & vbTab & vbTab & _
                lvw.SelectedItem.ListSubItems(1).Text & vbNewLine & vbTab & _
                lvw.SelectedItem.ListSubItems(2).Text
        End Select
    End Sub
    Last edited by 4x2y; Oct 21st, 2017 at 09:07 PM.



  6. #6
    Fanatic Member Spooman's Avatar
    Join Date
    Mar 2017
    Posts
    868

    Re: I can' find a title to this issue!!!

    Sam

    Here is another solution that uses LaVolpe's suggestion .. ie, the use of vbTab

    There are several key considerations:

    1. The length of the string
      • You can't always use a constant number of tabs
      • The number needs to take into account the length of the string, where length is pixels, not characters
      • Use the TextWidth Method to establish the length
    2. The length of vbTab .. will be font dependent
    3. Determine the max and min number of tabs required
    4. Add tabs as required


    Here is an image

    1. The top control is the ListView
      • Awid is the TextWidth of Author + 1 space
      • tabs is the number of tabs in Author .. ie, in Awid
        • in this case, TextWidth(.SelectedItem.Text & " ") / 840
        • where the width of vbTab is 840 (in this case)
    2. The 2nd control is Text2 .. it always uses 1 vbTab
      • shown for demo purposes only
      • ie, what NOT to do
    3. The 3rd control is Text4 .. it adds an extra vbTab as needed


    Notice that Text2 .. not aligned
    Notice that Text4 .. IS aligned

    Name:  Samer8.png
Views: 201
Size:  11.4 KB

    Here is a code snippet ...

    Code:
    Private Sub ListView1_Click()
       '
            With ListView1
                ' 1. initial 4 selections
                If samSel = Empty Then
                    ' 0. determine tab width
                    txt0 = "1" & vbTab
                    tw0 = TextWidth(txt0)       ' 840
                    tabwid = tw0
                    '
                    minrawtab = samMinTxWd / tabwid
                    minnntab = Int(minrawtab) + 1
                    maxrawtab = samMaxTxWd / tabwid
                    maxnntab = Int(maxrawtab) + 1
                    ' orig
                    ClickNum = ClickNum + 1
                    Select Case ClickNum
                        Case 1
                            ' w/ 1 tab
                            Text2.Text = "  " _
                                & "1-" _
                                & " " _
                                & .SelectedItem.Text _
                                & vbTab _
                                & .SelectedItem.ListSubItems(1).Text _
                                & vbNewLine _
                                & vbTab _
                                & .SelectedItem.ListSubItems(2).Text
                            ' w/ nn tabs
                            txwd = TextWidth(.SelectedItem.Text & " ")
                            rawtabs = txwd / tabwid
                            iitabs = Int(rawtabs)
                            nntabs = maxnntab - iitabs
                            Text4.Text = "  " _
                                & "1-" _
                                & " " _
                                & .SelectedItem.Text _
                                & vbTab _
                                & IIf(nntabs = 2, vbTab, "") _
                                & .SelectedItem.ListSubItems(1).Text _
                                & vbNewLine _
                                & vbTab _
                                & .SelectedItem.ListSubItems(2).Text
                        Case Is >= 2
                            ' w/ 1 tab
                            Text2.Text = Text2.Text _
                                & vbNewLine _
                                & vbNewLine _
                                & "  " _
                                & CInt(ClickNum) & "-" _
                                & " " _
                                & .SelectedItem.Text _
                                & vbTab _
                                & .SelectedItem.ListSubItems(1).Text _
                                & vbNewLine _
                                & vbTab _
                                & .SelectedItem.ListSubItems(2).Text
                            ' w/ nn tabs
                            txwd = TextWidth(.SelectedItem.Text & " ")
                            rawtabs = txwd / tabwid
                            iitabs = Int(rawtabs)
                            nntabs = maxnntab - iitabs
                            '
                            Text4.Text = Text4.Text _
                                & vbNewLine _
                                & vbNewLine _
                                & "  " _
                                & CInt(ClickNum) & "-" _
                                & " " _
                                & .SelectedItem.Text _
                                & vbTab _
                                & IIf(nntabs = 2, vbTab, "") _
                                & .SelectedItem.ListSubItems(1).Text _
                                & vbNewLine _
                                & vbTab _
                                & .SelectedItem.ListSubItems(2).Text
                    End Select
            End With
       '
    End Sub
    ... where the key is this line of code .. for Case 1
    Code:
                        Case 1
                            ' w/ nn tabs
                            txwd = TextWidth(.SelectedItem.Text & " ")
                            rawtabs = txwd / tabwid
                            iitabs = Int(rawtabs)
                            nntabs = maxnntab - iitabs
                            Text4.Text = "  " _
                                & "1-" _
                                & " " _
                                & .SelectedItem.Text _
                                & vbTab _
                                & IIf(nntabs = 2, vbTab, "") _
                                & .SelectedItem.ListSubItems(1).Text _
                                & vbNewLine _
                                & vbTab _
                                & .SelectedItem.ListSubItems(2).Text
    .. with a similar line of code for Case Is >= 2

    Indeed, if there is a really large difference in TextWidth's, extra IIf()'s may be needed

    There are a few other code frags involved.
    Holler if you'd like to see them.
    Natch, modify as needed.

    BTW, no API's required ..

    Spoo
    Last edited by Spooman; Oct 22nd, 2017 at 01:31 AM. Reason: BTW

  7. #7

    Thread Starter
    Fanatic Member
    Join Date
    Oct 2013
    Posts
    783

    Re: I can' find a title to this issue!!!

    4x2y
    Spooman
    You are great men.
    I thank you very much.
    As I expected the miracles are possible on Vbforums.
    Gentelmen: What you are doing encouraged me to ask this question:
    Is it possible to change the tab (space) at runtime by code?
    thanks a lot.

  8. #8
    Fanatic Member Spooman's Avatar
    Join Date
    Mar 2017
    Posts
    868

    Re: I can' find a title to this issue!!!

    Quote Originally Posted by samer22 View Post
    Gentelmen: What you are doing encouraged me to ask this question:
    Is it possible to change the tab (space) at runtime by code?
    Can't speak for 4x2y, but in my code snippet, the number of tabs DOES change at runtime

    Spoo

  9. #9
    PowerPoster
    Join Date
    Sep 2006
    Location
    Egypt
    Posts
    2,579

    Re: I can' find a title to this issue!!!

    Add the following sub to your code and call it with desired values
    (I'm not on computer to test, but it should work)

    Code:
    Private Sub SetTabWidth(ByVal t1 As Long, ByVal t2 As Long)
        Dim lngTabStop(1) As Long
        lngTabStop(0) = t1
        lngTabStop(1) = t2
        SendMessage Text1.hwnd, EM_SETTABSTOPS, 2, lngTabStop(0)
        Text1.Refresh
    End Sub



  10. #10

    Thread Starter
    Fanatic Member
    Join Date
    Oct 2013
    Posts
    783

    Re: I can' find a title to this issue!!!

    Spooman
    Thanks a lot
    In fact, I'm using 4x2y' code and it's working perfectly.
    because I need to use the item click event instead of the lvw_click event.
    thank you sir again.

  11. #11

    Thread Starter
    Fanatic Member
    Join Date
    Oct 2013
    Posts
    783

    Re: I can' find a title to this issue!!!

    4x2y
    Million thanks for your precious help.
    I found big trouble to call the subroutine under a button click.
    Could you please tellme how to do?
    thanks a lot.

  12. #12
    VB-aholic & Lovin' It LaVolpe's Avatar
    Join Date
    Oct 2007
    Location
    Beside Waldo
    Posts
    19,541

    Re: I can' find a title to this issue!!!

    Quote Originally Posted by samer22 View Post
    I found big trouble to call the subroutine under a button click.
    Could you please tellme how to do?
    thanks a lot.
    The itemclick event is for a single item. If you want to transfer all items to the textbox, you would loop through the items and send each one to that event, something like this:
    Code:
    Dim n As Long
    For n= 1 To lvw.ListItems.Count
        Call lvw_ItemClick(lvw.ListItems(n))
    Next
    Likewise, if just wanting to send the selected item only
    Code:
    Call lvw_ItemClick(lvw.SelectedItem)
    However, I'd suggest moving the code from the lvw_ItemClick event to your own custom subroutine. That way you can call it from wherever you need and the code wouldn't be tied to a specific event.
    Insomnia is just a byproduct of, "It can't be done"

    Classics Enthusiast? Here's my 1969 Mustang Mach I Fastback. Her sister '67 Coupe has been adopted

    Newbie? Novice? Bored? Spend a few minutes browsing the FAQ section of the forum.
    Read the HitchHiker's Guide to Getting Help on the Forums.
    Here is the list of TAGs you can use to format your posts
    Here are VB6 Help Files online


    {Alpha Image Control} {Memory Leak FAQ} {Unicode Open/Save Dialog} {Resource Image Viewer/Extractor}
    {VB and DPI Tutorial} {Manifest Creator} {UserControl Button Template} {stdPicture Render Usage}

  13. #13

    Thread Starter
    Fanatic Member
    Join Date
    Oct 2013
    Posts
    783

    Re: I can' find a title to this issue!!!

    Thank you LaVolpe
    In fact I'm referring to 4x2y subroutine.

    Code:
    Private Sub SetTabWidth(ByVal t1 As Long, ByVal t2 As Long)
        Dim lngTabStop(1) As Long
        lngTabStop(0) = t1
        lngTabStop(1) = t2
        SendMessage Text1.hwnd, EM_SETTABSTOPS, 2, lngTabStop(0)
        Text1.Refresh
    End Sub
    How shall I call this sub?
    thank you sir

  14. #14
    Fanatic Member Spooman's Avatar
    Join Date
    Mar 2017
    Posts
    868

    Re: I can' find a title to this issue!!!

    Quote Originally Posted by samer22 View Post
    Spooman
    Thanks a lot
    In fact, I'm using 4x2y' code and it's working perfectly.
    because I need to use the item click event instead of the lvw_click event.
    thank you sir again.
    Sam

    My bad .. I had not noticed the way you defined the sub in your post #1 ..
    However, now I'm a little confused

    In my post #6 I used
    Code:
    Private Sub ListView1_Click()
       '
    End Sub

    But ...

    .. if I rename the sub as ...
    Code:
    Private Sub ListView1_ItemClick(ByVal Item As MSComctlLib.ListItem)
       '
    End Sub
    ... or ...
    Code:
    Private Sub ListView1_ItemClick(ByVal Item As ListItem)
       '
    End Sub
    ... I get identical results
    In all 3 cases, the subs trigger ONLY IF items in the 1st column (ie, Author) are clicked

    My knowledge of ListView is limited. To those in the know ..
    1. what is the difference between the 3 sub definitions ?
    2. and why do they all produce identical results ?


    Spoo

  15. #15

    Thread Starter
    Fanatic Member
    Join Date
    Oct 2013
    Posts
    783

    Re: I can' find a title to this issue!!!

    I think I got it

    Code:
    SetTabWidth 100, 160
    Thanks

  16. #16

    Thread Starter
    Fanatic Member
    Join Date
    Oct 2013
    Posts
    783

    Re: I can' find a title to this issue!!!

    Spooman
    I didn't know if your code can be used under item click event.
    In my project I'm using the item clik and itemcheck events.

    to export items I use the itemclik
    to delete items I use the item-check.
    But if using lvw_click to export, the items are exported when checked.
    this is why I needed the item click event

  17. #17

    Thread Starter
    Fanatic Member
    Join Date
    Oct 2013
    Posts
    783

    Re: I can' find a title to this issue!!!

    Now I'll play a little with my code then close the post
    thank you

  18. #18
    Fanatic Member Spooman's Avatar
    Join Date
    Mar 2017
    Posts
    868

    Re: I can' find a title to this issue!!!

    Sam

    Sounds good to me.

    BTW, I checked the IDE's Help for ListView control, and ItemCheck is NOT listed among Events.
    However, if I search for ItemCheck event, it's there, plain as day !
    Go figure.

    Learned something new .. thanks

    Spoo

  19. #19

    Thread Starter
    Fanatic Member
    Join Date
    Oct 2013
    Posts
    783

    Re: I can' find a title to this issue!!!

    My friends I'm sorry to disturb you again.
    Code:
    Private Sub SetTabWidth(ByVal t1 As Long, ByVal t2 As Long)
        Dim lngTabStop(1) As Long
        lngTabStop(0) = t1
        lngTabStop(1) = t2
        SendMessage Text1.hwnd, EM_SETTABSTOPS, 2, lngTabStop(0)
        Text1.Refresh
    End Sub
    Is it possible to know the number of vbtabs and store these values in an ini or texfile.
    thank you
    Last edited by samer22; Oct 22nd, 2017 at 01:19 PM.

  20. #20
    PowerPoster
    Join Date
    Sep 2006
    Location
    Egypt
    Posts
    2,579

    Re: I can' find a title to this issue!!!

    Quote Originally Posted by samer22 View Post
    Is it possible to know the number of vbtabs and store these values in an ini or texfile.
    Are you save Tabs only not whole text?

    Try this
    Code:
    Private Function GetTabCount(ByVal strText As String) As Long
        Dim c As Long
        Dim j As Long
        
        For j = 1 To Len(strText)
            If Mid$(strText, j, 1) = vbTab Then
                c = c + 1
            End If
        Next
        GetTabCount = c
    End Function
    Usage
    Code:
    Private Sub Command1_Click()
        MsgBox GetTabCount(Text1.Text), vbOKOnly + vbInformation
    End Sub



  21. #21

    Thread Starter
    Fanatic Member
    Join Date
    Oct 2013
    Posts
    783

    Re: I can' find a title to this issue!!!

    Thank you sir
    But I'm a bit confused.
    The function you provided is really what I need and apparently it returns the right number of vbtabs.
    However, there is a problem.
    When calculating the vbtabs by means of the function it gives 3 vbtabs and that seems the corret value.
    Suppose I store this value.
    When I call this value using the subroutine, the values are initially:
    Code:
    SetTabWidth 100, 160
    Where am I going to put the stored value 3.
    Code:
    SetTabWidth 100, 3
    seems impossible.
    I hope you will understand my worry.
    thank you

  22. #22
    PowerPoster
    Join Date
    Sep 2006
    Location
    Egypt
    Posts
    2,579

    Re: I can' find a title to this issue!!!

    Tabstops are not how much the Text1.Text contain vbTab characters, but they are describe the location the cursor stops after vbTab character, most word processors uses Tabstops to enable the user to align text by pressing the tab key.

    The following screenshot is taken from Windows Write program, as you can see there are only two Tabstops but many Tab characters

    Name:  tabstops_2.jpg
Views: 162
Size:  16.0 KB



    I have declared the array lngTabStop with 2 values only because your output text don't requires more.

    I hope this is clear to you.



  23. #23

    Thread Starter
    Fanatic Member
    Join Date
    Oct 2013
    Posts
    783

    Re: I can' find a title to this issue!!!

    thanks sir
    I understand
    So what I'm looking for is to calculate this space maybe in text_change event.
    Name:  line.png
Views: 155
Size:  2.8 KB
    Then restore it whenever I wish.
    Is this possible?

  24. #24
    PowerPoster
    Join Date
    Sep 2006
    Location
    Egypt
    Posts
    2,579

    Re: I can' find a title to this issue!!!

    Quote Originally Posted by samer22 View Post
    thanks sir
    I understand
    So what I'm looking for is to calculate this space maybe in text_change event.
    Name:  line.png
Views: 155
Size:  2.8 KB
    Then restore it whenever I wish.
    Is this possible?
    That space is defined by the two values passed to SetTabWidth method, so all you need is saving these values and call SetTabWidth again with saved values.



  25. #25

    Thread Starter
    Fanatic Member
    Join Date
    Oct 2013
    Posts
    783

    Re: I can' find a title to this issue!!!

    Quote Originally Posted by 4x2y View Post
    That space is defined by the two values passed to SetTabWidth method, so all you need is saving these values and call SetTabWidth again with saved values.
    Would you please give me an example.
    Something like:
    Debug.Print values
    thanks

  26. #26
    PowerPoster
    Join Date
    Sep 2006
    Location
    Egypt
    Posts
    2,579

    Re: I can' find a title to this issue!!!

    SetTabWidth should called only once at program start (usually in Form_Load). Do you call it after that with different values? If so then save the new values to your settings file and in Form_Load read from settings file, something like this


    Code:
    Private Sub Form_Load()
        ' Here you should read t1 and t2 from your settings file
        SetTabWidth t1, t2
    End Sub
    Code:
    Private Sub SetTabWidth(ByVal t1 As Long, ByVal t2 As Long)
        Dim lngTabStop(1) As Long
        lngTabStop(0) = t1
        lngTabStop(1) = t2
        SendMessage Text1.hwnd, EM_SETTABSTOPS, 2, lngTabStop(0)
        Text1.Refresh
        ' Here you should save t1 and t2 to your settings file
    End Sub
    I hope you got the idea.



  27. #27

    Thread Starter
    Fanatic Member
    Join Date
    Oct 2013
    Posts
    783

    Re: I can' find a title to this issue!!!

    thanks sir
    I understand quite well.
    However what I wish to reach is something else.
    Let's explain:
    A user clicks on an item in the listview.
    The item(s) is exported to the textbox.
    Current formatting is quite satisfactory, but a user may change the initial formating by shortening or widening the space shown in the picture above.
    This means that the intial space ( t1, t2) has been changed.
    now, I need to pick these new values of t1 and t2 under the textbox change event and save them.
    I don't know wether this is possible or not?
    thank you

  28. #28

    Thread Starter
    Fanatic Member
    Join Date
    Oct 2013
    Posts
    783

    Re: I can' find a title to this issue!!!

    please help if possible
    Last edited by samer22; Oct 23rd, 2017 at 06:30 PM.

  29. #29
    PowerPoster
    Join Date
    Sep 2006
    Location
    Egypt
    Posts
    2,579

    Re: I can' find a title to this issue!!!

    Quote Originally Posted by samer22 View Post
    Current formatting is quite satisfactory, but a user may change the initial formating by shortening or widening the space shown in the picture above.
    If this text box is editable by the user, aren't you have to save his whole changes not just formatting?



  30. #30

    Thread Starter
    Fanatic Member
    Join Date
    Oct 2013
    Posts
    783

    Re: I can' find a title to this issue!!!

    Quote Originally Posted by 4x2y View Post
    If this text box is editable by the user, aren't you have to save his whole changes not just formatting?
    No I don't need to save the content of the textbox.
    I'm just interested in the layout.
    My question:
    Is it possible to detect (t1 and t2) while editing the text?
    thank you

  31. #31
    PowerPoster
    Join Date
    Sep 2006
    Location
    Egypt
    Posts
    2,579

    Re: I can' find a title to this issue!!!

    Quote Originally Posted by samer22 View Post
    Is it possible to detect (t1 and t2) while editing the text?
    It is possible if you let the user change them not the text itself, that is set Text1.ReadOnly to True and add HScroll1 and HScroll2 to your form and use code like this

    Code:
    Private Sub HScroll1_Change()
        SetTabWidth HScroll1.Value, HScroll2.Value
        ' Save HScroll1.Value and HScroll2.Value to your settings file.
        ' in Form_Load call SetTabWidth with above saved values
    End Sub
    
    Private Sub HScroll2_Change()
        SetTabWidth HScroll1.Value, HScroll2.Value
        ' Save HScroll1.Value and HScroll2.Value to your settings file.
        ' in Form_Load call SetTabWidth with above saved values
    End Sub
    I suggest using HScroll control but you are free to use any other input method.



  32. #32

    Thread Starter
    Fanatic Member
    Join Date
    Oct 2013
    Posts
    783

    Re: I can' find a title to this issue!!!

    You are a programmer of genius.
    Though the method does not meet exactly what I was wishing, it is creative and ingenious.
    I tested it and it is working perfect
    The read-only property doesn't fit the situation.
    Congratulation sir

  33. #33
    PowerPoster
    Join Date
    Sep 2006
    Location
    Egypt
    Posts
    2,579

    Re: I can' find a title to this issue!!!

    Great



  34. #34

    Thread Starter
    Fanatic Member
    Join Date
    Oct 2013
    Posts
    783

    Re: I can' find a title to this issue!!!

    Spooman
    Using your code in #6, I couldn't get the same alignement.
    Could you please attach a sample.
    thanks

  35. #35
    Fanatic Member Spooman's Avatar
    Join Date
    Mar 2017
    Posts
    868

    Re: I can' find a title to this issue!!!

    Sam

    Here is the snippet I used to load the ListView

    Code:
    Public ClickNum
    Dim aaSam(2, 4)
    Public samXdn
    Public samNN As Integer
    Public samSel As Integer
    Public samMaxTxWd As Integer
    Public samMinTxWd As Integer
    '
    Private Sub Command1_Click()
            With ListView1
                .Visible = True
                .Top = 300
                .Left = 300
                .Width = 4720 
                .Height = 2500
                ' Add ColumnHeaders.
                ListView1.ColumnHeaders.Add , , "Author", 2500 
                ListView1.ColumnHeaders.Add , , "ID", 500, lvwColumnCenter
                ListView1.ColumnHeaders.Add , , "A wid", 1000
                ListView1.ColumnHeaders.Add , , "tabs", 700
                ' Set View property to Report.
                ListView1.View = lvwReport
                ' Set the Database to the BIBLIO.MDB database.
                fpBIB = "C:\Program Files (x86)\Microsoft Visual Studio\VB98\Biblio.mdb"
                Dim myDb1 As Database, myRs1 As Recordset
                Set myDb1 = DBEngine.Workspaces(0).OpenDatabase(fpBIB)
                ' Set the recordset to the "Authors" table.
                Set myRs1 = myDb1.OpenRecordset("Authors", dbOpenDynaset)
                ' Declare a variable to add ListItem objects.
                Dim itmX1 As ListItem
                samNN = 8
                ' lead
                txt1 = "  " _
                    & "1-" _
                    & "  "
                tw1 = TextWidth(txt1)
                tw2 = TextWidth(" ")            ' 45
                samMaxTxWd = 0
                samMinTxWd = 5000
                For ii = 1 To samNN
                    Set itmX1 = ListView1.ListItems.Add(, , CStr(myRs1!Author))   ' Author
                    ' 1. If the AuthorID field is not null, then set SubItem 1 to it.
                    If Not IsNull(myRs1!Au_id) Then
                        itmX1.SubItems(1) = CStr(myRs1!Au_id)
                    End If
                    ' 2. txt width
                    txt0 = .ListItems.Item(ii)
                    itmX1.SubItems(2) = TextWidth(txt0) + tw2
                    ' 3. calc tabs
                    If TextWidth(txt0) > samMaxTxWd Then
                        samMaxTxWd = TextWidth(txt0) + tw2
                    End If
                    If TextWidth(txt0) < samMinTxWd Then
                        samMinTxWd = TextWidth(txt0) + tw2
                    End If
                    itmX1.SubItems(3) = Format((TextWidth(txt0) + tw2) / 840, "#.##")
                    '
                    myRs1.MoveNext
                
                Next ii
            End With
        '
    End Sub
    You may need to change this file path.

    Note
    .. I used Sub Command1_Click()
    .. you may want to put it into Sub Form_Load()
    HTH

    Spoo

  36. #36

    Thread Starter
    Fanatic Member
    Join Date
    Oct 2013
    Posts
    783

    Re: I can' find a title to this issue!!!

    Spooman
    thanks
    but the code is about feeding a listview from database.
    And my concern is about alignement in textbox when sending items from a listview.

  37. #37
    VB-aholic & Lovin' It LaVolpe's Avatar
    Join Date
    Oct 2007
    Location
    Beside Waldo
    Posts
    19,541

    Re: I can' find a title to this issue!!!

    If there is a way to retrieve the current tab positions in a textbox, I am not aware of it. Per MSDN, the default is every 32 dialog units. So, unless there is a way to retrieve them, you will need to cache/remember the ones you set. After setting t1,t2, cache them somewhere along with a flag that they are set. Then when you change them, re-cache them.
    Code:
    Dim m_TabPositions As String
    
    Private Function TabPositionsExist() As Boolean
        TabPositionsExist = Not (m_TabPositions = vbNullString)
    End Function
    
    Private Sub SetTabPositions(t1 As Long, t2 As Long)
        m_TabPositions = t1 & "," & t2
        Dim lngTabStop(1) As Long
        lngTabStop(0) = t1
        lngTabStop(1) = t2
        SendMessage Text1.hWnd, EM_SETTABSTOPS, 2, lngTabStop(0)
        Text1.Refresh
    End Sub
    
    Private Sub GetTabPositions(t1 As Long, t2 As Long)
        ' t1 & t2 are filled or returned as zero if not previously set
        If m_TabPositions = vbNullString Then
            t1 = 0: t2 = 0
        Else
            t1 = CLng(Left$(m_TabPositions, InStr(m_TabPositions, ",") - 1))
            t2 = CLng(Mid$(m_TabPositions, InStr(m_TabPositions, ",") + 1))
        End If
    End Sub
    The above is just an idea. If it sounds like it will work, modify it as needed.

    Edited: Changed GetTabPositions to more resemble SetTabPositions
    Last edited by LaVolpe; Oct 25th, 2017 at 04:36 PM.
    Insomnia is just a byproduct of, "It can't be done"

    Classics Enthusiast? Here's my 1969 Mustang Mach I Fastback. Her sister '67 Coupe has been adopted

    Newbie? Novice? Bored? Spend a few minutes browsing the FAQ section of the forum.
    Read the HitchHiker's Guide to Getting Help on the Forums.
    Here is the list of TAGs you can use to format your posts
    Here are VB6 Help Files online


    {Alpha Image Control} {Memory Leak FAQ} {Unicode Open/Save Dialog} {Resource Image Viewer/Extractor}
    {VB and DPI Tutorial} {Manifest Creator} {UserControl Button Template} {stdPicture Render Usage}

  38. #38
    Fanatic Member Spooman's Avatar
    Join Date
    Mar 2017
    Posts
    868

    Re: I can' find a title to this issue!!!

    Quote Originally Posted by samer22 View Post
    Spooman
    thanks
    but the code is about feeding a listview from database.
    And my concern is about alignement in textbox when sending items from a listview.
    Post #35 is what populates the ListView
    I thought that is what you meant by "attach a sample"

    The code for alignment issues is (and was all along) shown in post #6.

    What is it that you are looking for?
    Please be specific

    Spoo
    Last edited by Spooman; Oct 25th, 2017 at 04:36 PM.

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