adaptive user control

anand.neeli

New member
Joined
Jun 27, 2009
Messages
4
Programming Experience
Beginner
Hi Experts,

i have a user control which opens a file and renders data in some specific format.
is there a way to make sure that each instance of user control operate on different file (which can be obtained from mail form)

To tell shortly, how can user control be loaded with some paramaters/data from main form?

Thanks in advance.
 
Sure, make a Sub New with parameters in the UC's code:
VB.NET:
Expand Collapse Copy
Private m_FileName As String
Public Sub New(ByVal fileName As String)
   InitializeComponent()
   m_FileName = filename
End Sub
Then when you create the UC it will look like this:
VB.NET:
Expand Collapse Copy
Dim uc As New UserControl1("C:\test.txt")
Or you can just have the m_FileName set to Public and call it when creating it:
VB.NET:
Expand Collapse Copy
Dim uc As New UserControl1
uc.m_FileName = "C:\test.txt"
 
Last edited:
I don't want to seem picky, but.
Fields should never be made public. The OP should create a Public Property for access to the m_Filename Field.
 
Back
Top