Dec 30, 2014 04:05 AM
(This post was last modified: Jun 23, 2015 12:14 PM by +Haze.)
My second tutorial here. This tutorial is more about the object orientation methods that can be used to tackle more complex programming solutions.
So in this tutorial I will explain and show you how you can add custom objects into controls. In general you can use this example with any windows control which you can add objects to. Like the ComboBox. TreeNode. This is just no exclusive to VB, It works on C# too, and I'm sure it would work on any object orientated language.
So Let's begin by designing our form first.
![[Image: gdKurGY.png]](https://i.imgur.com/gdKurGY.png)
Now that's done, we can now create our class Persion() where we will add our Properties and Methods.
![[Image: SqQdszL.png]](https://i.imgur.com/SqQdszL.png)
After we done that, we now subscribe to the Clicked Event for our add button.
Inside that sub routine we instantiate our persons class. When we Instantiate we use the New Keyword.
![[Image: rGdVDnx.png]](https://i.imgur.com/rGdVDnx.png)
In this context, what we're doing is creating a New copy of the Person class. So in simpler terms. Each time we Instanciate. We create a new stickman.
And we define this new stickman, by giving him a Firstname, Lastname, Age and his own HF UID.
So each time we click the add button, a new stick man will be created and his properties(Firstname) will be the value of the txtFirstname textbox and so forth. And then that person is now added to then using the listbox using the ListBox1.Items.Add() method
Finally, this is the most important bit of our tutorial. This is how we get back these objects that we have added into our listbox.
![[Image: gPUNo0d.png]](https://i.imgur.com/gPUNo0d.png)
The direct cast allows us to convert the SelectedItem object to the Person object/class we have inserted. And this way we can get back the object we had previously added and view all its unique properties.
Here is a short clip of the end result of this tut.
so you can see the uses of this type of programming technique. Allowing us to use objects to accomplish complex tasks. And thus making programming easier when you're faced with scenarios where this method could be useful.
Here are the the vb.net code on pastebin with syntax highlighting.
http://pastebin.com/wvPU8BbS
and here's the .Zip of the source code.
https://www.mediafire.com/?do58dtcuyu46pd3
enjoy.
Some feedback would be nice too




![[Image: vjPWhyy.gif]](https://i.imgur.com/vjPWhyy.gif)