Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Getting Value of Databound Composite Control Back to Form

Status
Not open for further replies.

Auguy

Programmer
May 1, 2004
1,206
0
36
US
I made a composite control from a maskedtextbox and a datetimepicker to make it easier for a user to enter a date with the keyboard. I also added a property to bind the dtp on the composite control to the bindingsource on my windows form (see below). I also set up a property to return the dtp vlaue. Without explicitly calling the value property and setting the correct data table column to this value, how do I get the value back to the form. I can use the code in the second block below but it seems like I should be able to bind this composite control and not have to call the value property. If I don't do it this way the form never sees the value set in the composite control. Must be a better way. Do I have to bind using a different method? Any suggestions? I would like it to behave like a normal datetimepicker.
Code:
'Property in Composite Control
Public Property propBindingSource() As BindingSource
    Get
      Return (bs)
    End Get
    Set(ByVal value As BindingSource)
      bs = New BindingSource
      bs = value
      dtpDate.DataBindings.Add("Text", bs, "InvoiceDate")
    End Set
  End Property
Code:
'Code in Form to Get the Value
dt.Rows(0).Item("InvoiceDate") = MyDateTimePicker1.propValue

Auguy
Sylvania/Toledo Ohio
 
The Set part of the property is the problem:

Set(ByVal value As BindingSource)

Change the ByVal to ByRef and it will pass the bindingsource from the parent, instead of passing a copy as with ByVal.

I used to rock and roll every night and party every day. Then it was every other day. Now I'm lucky if I can find 30 minutes a week in which to get funky. - Homer Simpson

Arrrr, mateys! Ye needs ta be preparin' yerselves fer Talk Like a Pirate Day!
 
Thanks. I tried that and I get error "set parameter cannot be declared byref". Do I need to change the property definition. Not sure I can do that.

Auguy
Sylvania/Toledo Ohio
 
Oops, my bad. I've never actually tried using ByRef in a property Set before...I just learned something.




I used to rock and roll every night and party every day. Then it was every other day. Now I'm lucky if I can find 30 minutes a week in which to get funky. - Homer Simpson

Arrrr, mateys! Ye needs ta be preparin' yerselves fer Talk Like a Pirate Day!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top