views:

750

answers:

1

I am looking for some information on how to properly implement data binding on a user created control.

My UserControl contains a Textbox, a Button, and a MonthCalendar. I am able to databind to the Textbox inside of my user control, however, I want to implement the databinding on the UserControl itself, and not reference to textbox inside the control.

I have attempted to set a Property as follows:

  <System.ComponentModel.Bindable(True)> _
Public Property BoundDate() As DateTime
    Get
      Return _currentSelectedDate
    End Get
    Set(ByVal value As DateTime)
      SetDateTime(value, True)
    End Set
  End Property

However, when I add a binding source to the control, the field does not populate with the data, it remains blank. Do I need to do something to make the data appear afterwards?

Can anyone direct me to a good tutorial, or if possible, explain it here. The project is written in VB.NET.

EDIT: I am implementing the DefaultBindingPropertyAttribute

A: 

What is the textbox bound to at this point? I'd suggest the following:

  1. In the user control load event, declaratively bind the text box to a private member variable, e.g. private _boundDate as DateTime
  2. Have you setter in your boundDate property update _boundDate

This looks like a pretty good read, although I haven't looked at it myself

matt eisenberg