Results 1 to 10 of 10

Thread: linked listbox or other lined control

  1. #1

    Thread Starter
    Fanatic Member mutley's Avatar
    Join Date
    Apr 2000
    Location
    Sao Paulo - Brazil
    Posts
    709

    Question linked listbox or other lined control

    Hi

    How can I to build a linked Lisbox, when walk in lisbox1 show data in lisbox2 ?

    I Search some example, but not found

    Tia

  2. #2
    PowerPoster
    Join Date
    Feb 2012
    Location
    West Virginia
    Posts
    14,206

    Re: linked listbox or other lined control

    You would need to write some code to display what you want in list2 which gets executed when you select an item in list1.

  3. #3

    Thread Starter
    Fanatic Member mutley's Avatar
    Join Date
    Apr 2000
    Location
    Sao Paulo - Brazil
    Posts
    709

    Question Re: linked listbox or other lined control

    Quote Originally Posted by DataMiser View Post
    You would need to write some code to display what you want in list2 which gets executed when you select an item in list1.
    When Choice Listbox1 , show me data in listbox 2 etc, how can to do it ?

    Name:  figura01.jpg
Views: 355
Size:  10.1 KB
    Name:  figura02.jpg
Views: 346
Size:  8.7 KB
    Name:  figura03.jpg
Views: 468
Size:  10.4 KB

  4. #4
    PowerPoster
    Join Date
    Feb 2012
    Location
    West Virginia
    Posts
    14,206

    Re: linked listbox or other lined control

    If you are looking for that type of display then listboxes would not be my first choice.
    VB includes controls that do this easily. namely the drivelistbox, dirlistbox and filelistbox controls.

    It takes only one line of code in the drivelist and one line in the dir list to handle what you are doing

    In the drivelist change event you simply use
    Code:
    dir1.path=drive1.path
    and in the dirlist change event you use
    Code:
    file1.path=dir1.path
    The file list also has a pattern property so you can show only files that match a given pattern such as "*.txt" for example


    If you want to do it with regular list boxes then you will have to write code to put entries into the list boxes as needed.

  5. #5
    PowerPoster Elroy's Avatar
    Join Date
    Jun 2014
    Location
    Near Nashville TN
    Posts
    10,909

    Re: linked listbox or other lined control

    @mutley, I'm assuming your drives/folders/files is just an example. However, even with that example, it makes me think that you should look into the treeview control. For lists with a hierarchical nature, it's the perfect control.

    However, I must admit that I do some things somewhat similar to what you're suggesting. Basically, I just always do my work in the ListBox_Click event, more-or-less reserving the ListBox_DblClick event to do something further with the item.

    I also occasionally use the ListView control when there's just one level to the hierarchy. The following is a form with three separate ListViews on it. On two of the three ListView controls, you can clearly see where there's a hierarchical structure. I also (more-or-less) also achieve a third level of the hierarchy with the use of tooltips.

    Just some ideas for you. It'd be nice if you outlined what you're actually trying to do.

    Regards,
    Elroy

    Name:  p.jpg
Views: 364
Size:  61.9 KB
    Any software I post in these forums written by me is provided "AS IS" without warranty of any kind, expressed or implied, and permission is hereby granted, free of charge and without restriction, to any person obtaining a copy. To all, peace and happiness.

  6. #6

    Thread Starter
    Fanatic Member mutley's Avatar
    Join Date
    Apr 2000
    Location
    Sao Paulo - Brazil
    Posts
    709

    Question Re: linked listbox or other lined control

    Quote Originally Posted by Elroy View Post
    @mutley, I'm assuming your drives/folders/files is just an example. However, even with that example, it makes me think that you should look into the treeview control. For lists with a hierarchical nature, it's the perfect control.

    However, I must admit that I do some things somewhat similar to what you're suggesting. Basically, I just always do my work in the ListBox_Click event, more-or-less reserving the ListBox_DblClick event to do something further with the item.

    I also occasionally use the ListView control when there's just one level to the hierarchy. The following is a form with three separate ListViews on it. On two of the three ListView controls, you can clearly see where there's a hierarchical structure. I also (more-or-less) also achieve a third level of the hierarchy with the use of tooltips.

    Just some ideas for you. It'd be nice if you outlined what you're actually trying to do.

    Regards,
    Elroy

    Name:  p.jpg
Views: 364
Size:  61.9 KB
    Thank you for your answer

    But I put only example , I need two (or 3) listbox linked
    I have a textfile with 14 digits
    The digits can be
    1 ,2 3 4,5 6 7 , are combination the binary digits 001 => 1 , 010 => 2 , 100 => 4... 111 => 7
    [pre]
    11122444444444
    11242244444444
    11414244444444
    11414444444444
    12142444444444
    12224444444444
    12422244444444
    14144244444444
    14212244444444
    14212444444444
    14424444444444
    21144444444444
    21224244444444
    21422444444444
    22112444444444
    22214244444444
    22444244444444
    22444444444444
    24122244444444
    24242444444444
    24244444444444
    24412244444444
    41112244444444
    41214444444444
    41442444444444
    42124244444444
    42124444444444
    42242244444444
    42412444444444
    44114444444444
    44222444444444
    44444244444444
    11124222444444
    11142222444444
    11214222444444
    11412222444444
    11412422444444
    12242422444444
    12424422444444
    14144422444444
    14222222444444
    14414222444444
    21122222444444
    21142422444444
    21224422444444
    21444222444444
    22144222444444
    22214422444444
    22412222444444
    24112422444444
    24242222444444
    24244222444444
    24422422444444
    41114422444444
    41242422444444
    42122222444444
    42122422444444
    42224222444444
    42414222444444
    42442222444444
    44124222444444
    44212222444444
    44224422444444
    44444422444444
    11124224444444
    11222424444444
    11444424444444
    12112224444444
    12112424444444
    12244224444444
    12424424444444
    14122424444444
    14214424444444
    14442224444444
    21142224444444
    21142424444444
    21212224444444
    21414424444444
    22124424444444
    22222224444444
    22442424444444
    24114224444444
    24242424444444
    24244424444444
    24424224444444
    41114424444444
    41244224444444
    41422224444444
    41422424444444
    42144424444444
    42212424444444
    42414224444444
    44142224444444
    44224224444444
    44224424444444
    44412424444444
    11122442444444
    11244442444444
    12114242444444
    12114442444444
    12212242444444
    12422242444444
    12444242444444
    14112242444444
    14212442444444
    14224242444444
    14442442444444
    21114242444444
    21212442444444
    21442242444444
    22142242444444
    22222442444444
    22424242444444
    22444442444444
    24124442444444
    24242242444444
    24244242444444
    24414442444444
    41112242444444
    41144242444444
    41222242444444
    41424242444444
    41424442444444
    42244442444444
    42412442444444
    44142442444444
    44214242444444
    44422242444444
    [/pre]
    I must read this file text and for each row try to found other line with 1 or 2 digits different , if found I load other Listbox

    Then would Like when "walking" in listbox1 show me data in listbox2

    Name:  EXEMPLO2.jpg
Views: 252
Size:  16.4 KB

    After way to do It , I put a other listbox and a button and to choice what line to join with other, Example

    11122444444444
    12142444444444
    13162444444444

    There are two differences 2th and 4th digits then I make a OR operation
    1 or 2 => 3
    2 or 4 ==> 6
    two line turn one => 13162444444444

    I would like to know how can I to Link 2 listbox as runs through the lines
    Attached Images Attached Images  

  7. #7
    PowerPoster
    Join Date
    Feb 2012
    Location
    West Virginia
    Posts
    14,206

    Re: linked listbox or other lined control

    That is far from the first example you showed and takes us back to what I said at first which is that you will have to write code to populate the list with what you want to see in it.

    In other words when an item is selected in list1 you need to execute some code that clears list2 and adds items to list 2 based on what was selected in list one.

    There is no way to link list boxes, it is just a matter of rebuilding the list.

  8. #8

    Thread Starter
    Fanatic Member mutley's Avatar
    Join Date
    Apr 2000
    Location
    Sao Paulo - Brazil
    Posts
    709

    Question Re: linked listbox or other lined control

    Quote Originally Posted by DataMiser View Post
    That is far from the first example you showed and takes us back to what I said at first which is that you will have to write code to populate the list with what you want to see in it.

    In other words when an item is selected in list1 you need to execute some code that clears list2 and adds items to list 2 based on what was selected in list one.

    There is no way to link list boxes, it is just a matter of rebuilding the list.
    Thank you very much

    Then the only way to do is when click a item lisbox1 I must clear listbox 2 and rebuild ?

  9. #9
    PowerPoster
    Join Date
    Feb 2012
    Location
    West Virginia
    Posts
    14,206

    Re: linked listbox or other lined control

    Either that or have multiple listboxes that are not visible and show the one that has in it what you want when you want it.

  10. #10
    PowerPoster Elroy's Avatar
    Join Date
    Jun 2014
    Location
    Near Nashville TN
    Posts
    10,909

    Re: linked listbox or other lined control

    Code:
    
    Option Explicit
    '
    Dim vAy As Variant
    '
    
    Private Sub Form_Load()
        Dim i As Long
        vAy = Array("11122444444444", "11242244444444", "11414244444444", "11414444444444", "12142444444444", "12224444444444", "12422244444444", "14144244444444", "14212244444444", _
                    "14212444444444", "14424444444444", "21144444444444", "21224244444444", "21422444444444", "22112444444444", "22214244444444", "22444244444444", "22444444444444", _
                    "24122244444444", "24242444444444", "24244444444444", "24412244444444", "41112244444444", "41214444444444", "41442444444444", "42124244444444", "42124444444444", _
                    "42242244444444", "42412444444444", "44114444444444", "44222444444444", "44444244444444", "11124222444444", "11142222444444", "11214222444444", "11412222444444", _
                    "11412422444444", "12242422444444", "12424422444444", "14144422444444", "14222222444444", "14414222444444", "21122222444444", "21142422444444", "21224422444444", _
                    "21444222444444", "22144222444444", "22214422444444", "22412222444444", "24112422444444", "24242222444444", "24244222444444", "24422422444444", "41114422444444", _
                    "41242422444444", "42122222444444", "42122422444444", "42224222444444", "42414222444444", "42442222444444", "44124222444444", "44212222444444", "44224422444444", _
                    "44444422444444", "11124224444444", "11222424444444", "11444424444444", "12112224444444", "12112424444444", "12244224444444", "12424424444444", "14122424444444", _
                    "14214424444444", "14442224444444", "21142224444444", "21142424444444", "21212224444444", "21414424444444", "22124424444444", "22222224444444", "22442424444444", _
                    "24114224444444", "24242424444444", "24244424444444", "24424224444444", "41114424444444", "41244224444444", "41422224444444", "41422424444444", "42144424444444", _
                    "42212424444444", "42414224444444", "44142224444444", "44224224444444", "44224424444444", "44412424444444", "11122442444444", "11244442444444", "12114242444444", _
                    "12114442444444", "12212242444444", "12422242444444", "12444242444444", "14112242444444", "14212442444444", "14224242444444", "14442442444444", "21114242444444", _
                    "21212442444444", "21442242444444", "22142242444444", "22222442444444", "22424242444444", "22444442444444", "24124442444444", "24242242444444", "24244242444444", _
                    "24414442444444", "41112242444444", "41144242444444", "41222242444444", "41424242444444", "41424442444444", "42244442444444", "42412442444444", "44142442444444", _
                    "44214242444444", "44422242444444")
        '
        For i = LBound(vAy) To UBound(vAy)
            List1.AddItem vAy(i)
        Next i
    End Sub
    
    Private Sub List1_Click()
        Dim iDiff() As Long
        Dim s As String
        Dim iPtr As Long
        Dim iVal As Long
        Dim i As Long
        '
        If List1.ListIndex = -1 Then Exit Sub
        '
        s = List1.List(List1.ListIndex)
        '
        ReDim b2(LBound(vAy) To UBound(vAy))
        For i = LBound(vAy) To UBound(vAy)
            For iPtr = 1 To 14
                If Mid$(s, iPtr, 1) <> Mid$(vAy(i), iPtr, 1) Then b2(i) = b2(i) + 1
            Next iPtr
        Next i
        '
        List2.Clear
        For i = LBound(vAy) To UBound(vAy)
            If b2(i) = 1 Or b2(i) = 2 Then List2.AddItem vAy(i)
        Next i
    End Sub
    
    
    New project, List1 and List2 thrown onto Form1. And then the above code in Form1.

    That's at least one way to do it.

    Enjoy,
    Elroy

    p.s. I followed your specifications exactly. If you vary them, you may get errors.

    p.s. #2. I could highlight the differences the way you've done it using ListView, but not ListBox.
    Any software I post in these forums written by me is provided "AS IS" without warranty of any kind, expressed or implied, and permission is hereby granted, free of charge and without restriction, to any person obtaining a copy. To all, peace and happiness.

Tags for this Thread

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