R
Robert Styma
I have a question about private class visibility in
visual basic .net. I am using Visual Studio 2008.
I have a class supporting a windows form. Inside the
class, I have defined a private class to hold data.
Instances of this class get placed into a collection
which is public.
Normal procedure is to iterate (for each) through the
collection and pass the returned object to a method in
the class supporting the windows form which breaks out
the fields of the private class. This makes the private
interior class opaque to the outside.
While setting up some new code with copy and paste, I
discovered visual basic .net allowed me to access the
member variables of the private class from outside the
containing class.
1. Is this normal behavior?
2. If so, what is the point of having the interior class
be private?
Public Class EventData
Public AllEvents As New Microsoft.VisualBasic.Collection
....
Private Class EventEnt
Public EventCode As String
Public EventTitle As String
...
New() ...
New(with parameters)...
ToString() ...
End Class
End Class
In a different file:
Public Class Form1
' not using default instance
Public GblEventData As New EventData
...
Private Sub LoadGrid()
Dim M As Object
Dim Row As Integer = 0
' EventList is a DataGridView
Me.EventList.RowCount = Me.GblEventData.AllEvents.Count + 1
For Each M In Me.GblEventData.AllEvents
' Access to private class member?
' No error flagged and it appears to work fine!
Me.EventList.Item(0, Row).Value = M.EventCode
Me.EventList.Item(1, Row).Value = M.EventTitle
Row = Row + 1
Next M
Me.EventList.Sort(Me.EventList.Columns(0),_
System.ComponentModel.ListSortDirection.Ascending)
End Sub ' LoadGrid
PS: The more I learn about datagridview, the more I like it.
Thank you for a great control.
visual basic .net. I am using Visual Studio 2008.
I have a class supporting a windows form. Inside the
class, I have defined a private class to hold data.
Instances of this class get placed into a collection
which is public.
Normal procedure is to iterate (for each) through the
collection and pass the returned object to a method in
the class supporting the windows form which breaks out
the fields of the private class. This makes the private
interior class opaque to the outside.
While setting up some new code with copy and paste, I
discovered visual basic .net allowed me to access the
member variables of the private class from outside the
containing class.
1. Is this normal behavior?
2. If so, what is the point of having the interior class
be private?
Public Class EventData
Public AllEvents As New Microsoft.VisualBasic.Collection
....
Private Class EventEnt
Public EventCode As String
Public EventTitle As String
...
New() ...
New(with parameters)...
ToString() ...
End Class
End Class
In a different file:
Public Class Form1
' not using default instance
Public GblEventData As New EventData
...
Private Sub LoadGrid()
Dim M As Object
Dim Row As Integer = 0
' EventList is a DataGridView
Me.EventList.RowCount = Me.GblEventData.AllEvents.Count + 1
For Each M In Me.GblEventData.AllEvents
' Access to private class member?
' No error flagged and it appears to work fine!
Me.EventList.Item(0, Row).Value = M.EventCode
Me.EventList.Item(1, Row).Value = M.EventTitle
Row = Row + 1
Next M
Me.EventList.Sort(Me.EventList.Columns(0),_
System.ComponentModel.ListSortDirection.Ascending)
End Sub ' LoadGrid
PS: The more I learn about datagridview, the more I like it.
Thank you for a great control.