Quantcast
Channel: Windows Forms Data Controls and Databinding forum
Viewing all articles
Browse latest Browse all 2535

How to Bind Property of UserControl In DataRepeater

$
0
0

I want to use the free-form list layout in my WinForms app - therefore I cannot use DataGridView. I want to use DataRepeater (Visual Basic PowerPacks) and I need to place the User Control into the ItemTemplate.

The data object is simple:

class Class1
{
	public virtual int Index { get; set; }
}

I populate the DataRepeater in the Load event (DataRepeater is connected to the class1BindingSource object):

private List<Test.Class1> Sez = new List<Class1>();

private void Form1_Load(object sender, EventArgs e)
{
	Sez.Add(new Class1() { Index = 1 });
	class1BindingSource.DataSource = Sez;
}

My UC contains NumericUpDown control and therefore I published NumericUpDown1.Value as public property of my UC (in order to use it in binding):

public partial class UserControl1 : UserControl
{
	public decimal NudIndex
	{
		get
		{
			return numericUpDown1.Value;
		}
		set
		{
			numericUpDown1.Value = value;
		}
	}
	public UserControl1()
	{
		InitializeComponent();
	}
}

For testing purpose I put simple NumericUpDown (name indexNumericUpDown) to the ItemTemplate, too. These two NUDs I bind to the same data object (code snippets from the designer file):

this.userControl11.DataBindings.Add(new System.Windows.Forms.Binding("NudIndex", this.class1BindingSource, "Index", true));
...
this.indexNumericUpDown.DataBindings.Add(new System.Windows.Forms.Binding("Value", this.class1BindingSource, "Index", true));

When I run the app and change the simple indexNumericUpDown value, then the Sez[0].Index changes (change is propagated to UC, too). But when I change the NUD in UC, then Sez[0].Index nor indexNumericUpDowndo not change.

I tried to implement INotifyPropertyChanged - no help, I tried to change the UC property type to string - no help. What do I wrong?Why the User Control's control change does not propagate to the binded object(but indexNumericUpDown change does)? Thank you.

PS: VS2010, .NET 4.0, Win7 32.



Viewing all articles
Browse latest Browse all 2535

Trending Articles