All pastes #512216 Raw Edit

Anonymous

public text v1 · immutable
#512216 ·published 2007-05-26 20:03 UTC
rendered paste body
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Text;
using System.Windows.Forms;

namespace WindowsApplication7
{
	public partial class UserControl1 : UserControl
	{
		private Product m_BoundProduct;

		public UserControl1()
		{
			InitializeComponent();
		}

		public Product Product
		{
			get { return m_BoundProduct; }
			set 
			{
				if ( m_BoundProduct != value )
				{
					ClearBindings();
					m_BoundProduct = value;

					if ( m_BoundProduct != null )
					{
						Bind();
					}
				}
			}
		}

		private void ClearBindings()
		{
			this.textBox1.DataBindings.Clear();
		}

		private void Bind()
		{
			this.textBox1.DataBindings.Add( "Text", m_BoundProduct, "Name", true, DataSourceUpdateMode.OnPropertyChanged );
		}
	}
}