windows forms and arguments

  • Thread starter Thread starter Simon Whale
  • Start date Start date
S

Simon Whale

Hi,

i am writing a project that uses a treeview as its main application
navigation for the many parts of the program. i have one part when i need
to display customer information in a child window, i thought i would be able
to overide the new() in the form but this returns an error.

my question is what would be the best way off passing a argument from the
treeview to a form that i want to open? can somebody point me in the right
direction

Many thanks
Simon Whale
 
You can overload the constructor in a class:

Public Class TestClass
Public Sub New()
'Do nothing here
End Sub

Public Sub New(ByVal x As String)
'Set property here
_x = x
End Sub

'Field declaration
Private _x As String

'Proeprty declaration
Public Property X() As String
Get
Return _x
End Get
Set(ByVal Value As String)
_x = Value
End Set
End Property
End Class

--
Gregory A. Beamer
MVP; MCP: +I, SE, SD, DBA

***************************
Think Outside the Box!
***************************
 
As a follow up, since it may not be completely obvious that a form is just
another type of class. Here is a form constructor overloaded:

Public Sub New(ByRef x As String)
'Should always call default constructor
Me.New()

'Set field
_x = x
End Sub

To instantiate the form:

Dim f As New Form2("x")
f.Show()

--
Gregory A. Beamer
MVP; MCP: +I, SE, SD, DBA

***************************
Think Outside the Box!
***************************
 
Back
Top