Results 1 to 6 of 6

Thread: Problem using ObjectListView in VB.net

  1. #1

    Thread Starter
    Member
    Join Date
    Feb 2012
    Posts
    34

    Problem using ObjectListView in VB.net

    hi,
    Previously I try to learn add, edit and delete using ObjectListView in C# ( I still learn about C# )
    but now I try to use it in vb net, now I'm confuse how to addobject in vb, I don't know how to change C# to vb
    can someone help me how to add items to objectlistview ?

  2. #2
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: Problem using ObjectListView in VB.net

    The VB code will be almost exactly the same as the C# code. Given that we don't know what the C# code looks like though, we can hardly tell you what the equivalent VB looks like.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  3. #3

    Thread Starter
    Member
    Join Date
    Feb 2012
    Posts
    34

    Re: Problem using ObjectListView in VB.net

    in my C# code when I add to objectlistview I create a class to add my item to objectlistview
    my code will be like this


    Code:
            private void button1_Click(object sender, EventArgs e)
            {
                people pl = new people(txtName.Text, txtAddress.Text);            
                objectlistview1.AddObject(pl);
            }
    
    
            class people
            {
                public people(String name, string address)
                {
                    this.Name = name;
                    this.Address = address;
                }
    
                public string Name { get; set; }
                public string Address { get; set; }
            }
    that makes me confuse how i can change it to vb.. please help me how to change it to vb or how to add item to objectlistview

  4. #4
    PowerPoster dunfiddlin's Avatar
    Join Date
    Jun 2012
    Posts
    8,245

    Re: Problem using ObjectListView in VB.net

    This conversion site gives you ...

    Private Sub button1_Click(sender As Object, e As EventArgs)
    Dim pl As New people(txtName.Text, txtAddress.Text)
    objectlistview1.AddObject(pl)
    End Sub


    Private Class people
    Public Sub New(name As [String], address As String)
    Me.Name = name
    Me.Address = address
    End Sub

    Public Property Name() As String
    Get
    Return m_Name
    End Get
    Set
    m_Name = Value
    End Set
    End Property
    Private m_Name As String
    Public Property Address() As String
    Get
    Return m_Address
    End Get
    Set
    m_Address = Value
    End Set
    End Property
    Private m_Address As String
    End Class

    Looks about right to me.
    As the 6-dimensional mathematics professor said to the brain surgeon, "It ain't Rocket Science!"

    Reviews: "dunfiddlin likes his DataTables" - jmcilhinney

    Please be aware that whilst I will read private messages (one day!) I am unlikely to reply to anything that does not contain offers of cash, fame or marriage!

  5. #5
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: Problem using ObjectListView in VB.net

    The one thing that you'd need to add to the code that dunfiddlin posted is a Handles clause to the button1_Click. It is obviously intended to be a handler for the Click event of 'button1' so you would add 'Handles button1.Click' to the method declaration.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  6. #6

    Thread Starter
    Member
    Join Date
    Feb 2012
    Posts
    34

    Re: Problem using ObjectListView in VB.net

    thanks for the help.. the code works well for now
    I never know there is a web that can convert C# to vb.. thanks again
    Last edited by choco; Mar 2nd, 2013 at 03:23 AM.

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