CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 4 of 4

Hybrid View

  1. #1
    Join Date
    Feb 2003
    Location
    Holland
    Posts
    146

    [RESOLVED] Same listview on different forms

    In a project with several forms i use a listview with the same contents on each form.
    On form1 there is LvTijdvakken
    On form2 there is LvTijdvakken and so on.
    Is it possible to fill the LvTijdvakken on the different forms with one routine ?
    F.i. Call FillLvTijdvakken(form1)?

    Herman
    Last edited by HermanTabbert; September 18th, 2013 at 08:40 AM.

  2. #2
    Join Date
    Jul 2001
    Location
    Sunny South Africa
    Posts
    11,283

    Re: Same listview on different forms

    Yes, you have the right idea. You should just provide a parameter to your FillLvTijdvakken routine, I'm typing off the cuff here, so let us see :

    Code:
    Public Sub FillLvTijdvakken(frm as Form)
    
    .....
    frm.LvTijdvakken.LitsItems.Add(Whatever data) 'fill appropriate ListView here
    End Sub
    
    Call FillLvTijdvakken(Form2) ' call sub here with correct form ( meybe even use Me here as well )
    I hope it helps!

  3. #3
    Join Date
    Jul 2008
    Location
    WV
    Posts
    5,362

    Re: Same listview on different forms

    You could take it another step and pass the listview to the sub instead fo the form

    Place the sub in a module
    Code:
    Public Sub FillListView(TheList as ListView)
    
    With TheList    
        'Code to add items to the list
        ' i.e.  .ListItems.Add ......
    End With
    End Sub
    'to call the sub then in your form code you would use something like

    Code:
    FillListView LvTijdvakken
    Or if calling it from somewhere other than the form where it resides you would use
    Code:
    FillListView Form2.LvTijdvakken
    or
    Code:
    FillListView Form1.LvTijdvakken
    Note the Call keyword is not required in VB.

    I am really surprised how many people I see using it on the forums. I guess somewhere they still teach this but it has not been needed for at least 20 years now.
    Always use [code][/code] tags when posting code.

  4. #4
    Join Date
    Feb 2003
    Location
    Holland
    Posts
    146

    Re: Same listview on different forms

    Hannes and Datamiser thanks for your help.
    This is what works fine for me.

    Greetings from Holland,
    Herman

    Code:
    Public Sub VulDeTijdvakken(Frm As Form)
        Close #12
        TijdvakBestand = "c:\hatacom\source\lonen_2014\projecten\adm001\tijdvak12.13"
        Open TijdvakBestand For Random As #1 Len = Len(TV)
        For X = 1 To 8
            Get #1, X, TV
                With Frm
                    .LvTijdvakken.ListItems.Add , , TV.Periode
                    .LvTijdvakken.ListItems(.LvTijdvakken.ListItems.Count).SubItems(1) = TV.LoontijdVakBegin
                    .LvTijdvakken.ListItems(.LvTijdvakken.ListItems.Count).SubItems(2) = TV.LoontijdVakEind
                     Tempbestand = "c:\hatacom\source\lonen_2014\projecten\adm001\lonen" & Format(X, "##00") & "." & "13"
                     ' loonberekening
                     Temp = Format(FileDateTime(Tempbestand), "dd-mm-yyyy")
                    .LvTijdvakken.ListItems(.LvTijdvakken.ListItems.Count).SubItems(3) = Temp
                    ' Aangifte
                     Tempbestand = "c:\hatacom\source\lonen_2014\projecten\adm001\aangifte" & Format(X, "##00") & "13." & "xml"
                     Temp = Format(FileDateTime(Tempbestand), "dd-mm-yyyy")
                    .LvTijdvakken.ListItems(.LvTijdvakken.ListItems.Count).SubItems(4) = Temp
                End With
        Next X
    End Sub

    end code

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

Featured