Results 1 to 11 of 11

Thread: How can you add data to a listview located on another form?

  1. #1

    Thread Starter
    Frenzied Member
    Join Date
    Jul 2003
    Posts
    1,269

    How can you add data to a listview located on another form?

    anyone know?

  2. #2
    Hyperactive Member rplcmint's Avatar
    Join Date
    Jan 2001
    Location
    Stockton, CA
    Posts
    333
    Create a subroutine in a module like this:

    Public Module Module1


    Public Sub Add_Item(ByRef lvOne As ListView, ByVal sString As String)
    lvOne.Items.Add(sString.Trim)
    End Sub

    End Module

    In the first form, call this method:

    Call Module1.Add_Item(objForm.lvTwo, "SomeString")


    Basically you have the second form declared and instantiated and pass the ListView by reference along with a string you wish to populate inside.

    I hope this helps.

  3. #3

    Thread Starter
    Frenzied Member
    Join Date
    Jul 2003
    Posts
    1,269
    how can you declare an instantiate it ?

  4. #4

    Thread Starter
    Frenzied Member
    Join Date
    Jul 2003
    Posts
    1,269
    how can you declare an instantiate it ?

  5. #5
    Frenzied Member DevGrp's Avatar
    Join Date
    Nov 2001
    Location
    Charlotte, NC
    Posts
    1,256
    You can also use a delegate.

  6. #6

    Thread Starter
    Frenzied Member
    Join Date
    Jul 2003
    Posts
    1,269
    how? sorry im very new at vb.net

  7. #7
    Frenzied Member DevGrp's Avatar
    Join Date
    Nov 2001
    Location
    Charlotte, NC
    Posts
    1,256
    Forget what I said about using a delegate. This seems really simple. Where is the data coming from? If you want to add data to a listview, just open the form and add your data.

  8. #8

    Thread Starter
    Frenzied Member
    Join Date
    Jul 2003
    Posts
    1,269
    data is in form2, listview is in form1...

  9. #9
    Hyperactive Member rplcmint's Avatar
    Join Date
    Jan 2001
    Location
    Stockton, CA
    Posts
    333
    As I said before, place this in a module:

    Public Module Module1


    Public Sub Add_Item(ByRef lvOne As ListView, ByVal sString As String)
    lvOne.Items.Add(sString.Trim)
    End Sub

    End Module

    Now enter this code in Form2 (Maybe on a button click event or something

    Call Module1.Add_Item(Form1.ListView1, "Somestring")

    This should populate the listview on the first form.

    Work with that.

  10. #10
    Frenzied Member dynamic_sysop's Avatar
    Join Date
    Jun 2003
    Location
    Ashby, Leicestershire.
    Posts
    1,142
    in Form1 do this....
    VB Code:
    1. [color=blue]Private Sub[/color] Button1_Click([color=blue]ByVal[/color] sender [color=blue]As[/color] System.Object, [color=blue]ByVal[/color] e [color=blue]As[/color] System.EventArgs) [color=blue]Handles[/color] Button1.Click
    2.     [color=blue]Dim[/color] frm2 [color=blue]As New[/color] Form2()
    3.     [color=blue]MyBase[/color].AddOwnedForm(frm2) '/// make form2 owned by form1.
    4.     frm2.Show()
    5. [color=blue]End Sub[/color]
    in Form2....
    VB Code:
    1. [color=blue]Private Sub[/color] Button1_Click([color=blue]ByVal[/color] sender [color=blue]As[/color] System.Object, [color=blue]ByVal[/color] e [color=blue]As[/color] System.EventArgs) [color=blue]Handles[/color] Button1.Click
    2.     [color=blue]Dim[/color] frmMain [color=blue]As[/color] Form1 = [color=blue]MyBase[/color].Owner
    3.     frmMain.ListView1.Items.Add("some stuff from form2!")
    4. [color=blue]End Sub[/color]
    i've included a little demo to help it look easier...
    Attached Files Attached Files
    ~
    if a post is resolved, please mark it as [Resolved]
    protected string get_Signature(){return Censored;}
    [vbcode][php] please use code tags when posting any code [/php][/vbcode]

  11. #11

    Thread Starter
    Frenzied Member
    Join Date
    Jul 2003
    Posts
    1,269
    ty

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