|
-
Aug 17th, 2007, 09:27 AM
#1
Thread Starter
Hyperactive Member
[2005] Need help on Public sub new()
Hi I wanted to format datagridtextboxcolumn in .net compact framework 2.0which does not support format, so when I search for help from MSDN this sample code code was there but I am finding difficulty with the "sub new()" They said the code is the same in .net framework 2.0, so I would be grateful if anyone could help.
Visual Basic(declaration)
Code:
Public Sub New(_ prop AS PropertyDescriptor, _ Format As String _)
Visual Basic(Usage)
Dim prop As PropertyDescriptor
Dim format As String
Dim instance As New DataGridTextBoxColumn(prop, format)
Visaul Basic Code
Private Sub AddColumn()
Dim myTable As New DataTable()
' Add a new DataColumn to the DataTable.
Dim myColumn As New DataColumn("myTextBoxColumn")
myColumn.DataType = System.Type.GetType("System.String")
myColumn.DefaultValue = "default string"
myTable.Columns.Add(myColumn)
' Get the CurrencyManager for the DataTable.
Dim cm As CurrencyManager = CType(Me.BindingContext(myTable), CurrencyManager)
' Use the CurrencyManager to get the PropertyDescriptor for the new column.
Dim pd As PropertyDescriptor = cm.GetItemProperties()("myTextBoxColumn")
Dim myColumnTextColumn As DataGridTextBoxColumn
' Create the DataGridTextBoxColumn with the PropertyDescriptor.
myColumnTextColumn = New DataGridTextBoxColumn()
' Add the new DataGridColumn to the GridColumnsCollection.
dataGrid1.DataSource = myTable
dataGrid1.TableStyles.Add(New DataGridTableStyle())
dataGrid1.TableStyles(0).GridColumnStyles.Add(myColumnTextColumn)
End Sub 'AddColumn
The bold pd give error of "Too many argument on public sub new()"
I declare in the sub new as this
Code:
Public Sub New(ByVal prop As PropertyDescriptor, ByVal Format As String)
' This call is required by the Windows Form Designer.
InitializeComponent()
' Add any initialization after the InitializeComponent() call.
End Sub
This is the error I get
(Argument not specified for parameter "Format" of public sub New(prop as system.Componetmodel.PropertyDescriptor, Format as String)
and
(Argument not specified for parameter "Prop" of public sub New(prop as system.Componetmodel.PropertyDescriptor, Format as String)
I will be very much grateful if anyone could help me on the declaration and how to go about it. Thanks
-
Aug 17th, 2007, 10:38 AM
#2
Lively Member
Re: [2005] Need help on Public sub new()
Add this code to the file where the error ocurrs
vb.net Code:
Public Sub New()
' This call is required by the Windows Form Designer.
InitializeComponent()
' Add any initialization after the InitializeComponent() call.
End Sub
-
Aug 17th, 2007, 10:41 AM
#3
Re: [2005] Need help on Public sub new()
Since the Sub New is called when the program first starts, how do you intend to be passing anything to it? I'm not saying it can't be done, but....well, I've never heard of it being done in the CF, so I was wondering if you need to do it at all. If you don't, then get rid of the arguments and find a different way to get that information into the program.
Actually, the more I think of it, that Sub New seems a bit odd. Is that a typical starting point of a program, or is that supposed to be called as a sub in the program.
My usual boring signature: Nothing
 
-
Aug 17th, 2007, 11:02 AM
#4
Re: [2005] Need help on Public sub new()
It's the new constructor for a form (the InitializeComponent gives it away).....
Which means anytime you create a new instance of that form you HAVE to also pass the parameters to it as well.
1) I'm willing to guess that this form is setup as your default startup form. That's not going to work.
2) What you should have done is left the default constructor alone, and added a new one that then takes the parameters.
3) To use the constructor parameters.... and this is the part that is going t o bite... you'll need to turn off the Application Framework, add a new class, create a Public Sub Main .... dim your form, create an instance of the form (passing the parameters), then display the form. Then you'll need to set your startup object as Sub Main.
-tg
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|