When you write this:
Dim dgv As New DataGridView
dgv.Rows.Add(obj)
You create an instance of the DataGridView, and then use it:
dgv.Rows
is a Property of DataGridView which returns a n instance of the DataGridViewRowCollection class which is the rows in the DGV:
MSDN[
^]
The DataGridViewRowCollection has a Method
Add
which adds a row to the collection, and hence to the DGV.
To do something similar, you'd need an extra class:
Public Class MyColor
Public Sub ResetColor()
End Sub
End Class
Public Class Car
Public Property TheColor() As MyColor
Get
Return m_TheColor
End Get
Set
m_TheColor = Value
End Set
End Property
Private m_TheColor As MyColor
End Class
...
Public Sub myMethod()
Dim newCar As New Car()
newCar.TheColor.ResetColor()
End Sub
Quote:
an we do the similiar way to create property or method in another language? like java or c#. And is this a part of OOP concept? what did i miss in my learning of programming?
Yes. For example, the above in C# is:
public class MyColor
{
public void ResetColor()
{
}
}
public class Car
{
public MyColor TheColor { get; set; }
}
...
public void myMethod()
{
Car newCar = new Car();
newCar.TheColor.ResetColor();
}
And it's similar code for Java.
Properties aren't strictly part of OOPs - they are just "syntactic sugar" for the method calls involved that let you treat the property as a variable - but most OOPs languages implement them.
What did you miss? :laugh: I don't know, I wasn't there!