Data Binding and User Controls

N

ncarnal

I am binding to a UserControl:

MyControl.DataBindings.Add("MyProperty",bindingsource,"PropertyOfBindingSource")

Within my UserControl, I have setup INotifyPropertyChanged and I raise
the event PropertyChanged to tell the binding source I have made a
change to MyProperty. But no update is taking place.

MyProperty sets the Text value of a TextBox and conversely, anychanges
to the TextBox.Text property set the value of MyProperty.

Any ideas would be greatly appreciated.

Thanks

ncarnal
 
N

ncarnal

I am binding to a UserControl:

MyControl.DataBindings.Add("MyProperty",bindingsource,"PropertyOfBindingSource")

Within my UserControl, I have setup INotifyPropertyChanged and I raise
the event PropertyChanged to tell the binding source I have made a
change to MyProperty. But no update is taking place.

MyProperty sets the Text value of a TextBox and conversely, anychanges
to the TextBox.Text property set the value of MyProperty.

Any ideas would be greatly appreciated.

Thanks

ncarnal

I failed to include I am attempting to accomplish this with
WindowsForms 2.0.

Thanks

ncarnal
 
L

Larry Lard

I am binding to a UserControl:

MyControl.DataBindings.Add("MyProperty",bindingsource,"PropertyOfBindingSource")

Within my UserControl, I have setup INotifyPropertyChanged and I raise
the event PropertyChanged to tell the binding source I have made a
change to MyProperty. But no update is taking place.

MyProperty sets the Text value of a TextBox and conversely, anychanges
to the TextBox.Text property set the value of MyProperty.

Any ideas would be greatly appreciated.

Show us some code. Not everything: just enough
(<http://www.yoda.arachsys.com/csharp/complete.html>).
 
N

ncarnal

Show us some code. Not everything: just enough
(<http://www.yoda.arachsys.com/csharp/complete.html>).

--
Larry Lard
(e-mail address removed)
The address is real, but unread - please reply to the group
For VB and C# questions - tell us which version
Thanks for your inquiry. The costPickup is a CostLine.

Me.costPickup.DataBindings.Add("Cost", _bindingSource, "Pickup")

Public Class CostLine
Implements INotifyPropertyChanged

Private _labelFont As Font
Private _labelForeColor As Color
Private _percentFont As Font

Private _labelFontSelected As Font
Private _percentFontSelected As Font

Public Event PropertyChanged(ByVal sender As Object, ByVal e As
System.ComponentModel.PropertyChangedEventArgs) Implements
System.ComponentModel.INotifyPropertyChanged.PropertyChanged

Private _cost As Single
Public Property Cost() As Single
Get
Return _cost
End Get
Set(ByVal Value As Single)
_cost = Value
If _cost <= 0 Then
Me.curCost.Text = String.Empty
Else
Me.curCost.Text = _cost.ToString
End If
'.Item("Cost") = _cost
'MyBase.OnValidated(EventArgs.Empty)
FirePropertyChangedNotification("Cost")
End Set
End Property

Private Sub FirePropertyChangedNotification(ByVal propName As
String)
RaiseEvent PropertyChanged(Me, New
PropertyChangedEventArgs(propName))
End Sub
End Class

The data loads correctly from the BindingSource; however, no update is
made to the binding source upon changing the data in the costPickup
object.

Thanks again

nathan
 
L

Larry Lard

Thanks for your inquiry. The costPickup is a CostLine.
Me.costPickup.DataBindings.Add("Cost", _bindingSource, "Pickup")

Public Class CostLine
Implements INotifyPropertyChanged

Private _labelFont As Font
Private _labelForeColor As Color
Private _percentFont As Font

Private _labelFontSelected As Font
Private _percentFontSelected As Font

Public Event PropertyChanged(ByVal sender As Object, ByVal e As
System.ComponentModel.PropertyChangedEventArgs) Implements
System.ComponentModel.INotifyPropertyChanged.PropertyChanged

Private _cost As Single
Public Property Cost() As Single
Get
Return _cost
End Get
Set(ByVal Value As Single)
_cost = Value
If _cost <= 0 Then
Me.curCost.Text = String.Empty
Else
Me.curCost.Text = _cost.ToString
End If
'.Item("Cost") = _cost
'MyBase.OnValidated(EventArgs.Empty)
FirePropertyChangedNotification("Cost")
End Set
End Property

Private Sub FirePropertyChangedNotification(ByVal propName As
String)
RaiseEvent PropertyChanged(Me, New
PropertyChangedEventArgs(propName))
End Sub
End Class

The data loads correctly from the BindingSource; however, no update is
made to the binding source upon changing the data in the costPickup
object.

That looks OK from here. Right now I think the best thing would be for
you to post your question to
microsoft.public.dotnet.framework.windowsforms.databinding, because the
people there will probably be able to spot the problem more quickly than
me :) Include some more code too, like where you change the Cost
property, and the code that sets up the BindingSource. Enough to make a
functional program.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top