(c) 2003 Visual Studio Magazine 
Fawcette Technical Publications

C#	Bind a Record to Any Control
Listing 1	You can bind this simple version of an address record to any control. It exposes read/write properties for the various elements in an address.

public class AddressRecord
{
	/// <summary>
	/// Structure to hold the data.
	/// </summary>
	/// <remarks>
	/// A structure to store the data.
	/// </remarks>
	private struct AddressRecordData 
	{
		public string street;
		public string city;
		public string state;
		public string zip;
	}

	/// <summary>
	/// The permanent data store.
	/// </summary>
	private AddressRecordData permanentRecord;

	#region The specific Stuff
	/// <summary>
	/// Get and set the street.
	/// </summary>
	public string Street
	{
		get 
		{
			return permanentRecord.street;
		}
		set 
		{ 
				permanentRecord.street = value;
		}
	}

	/// <summary>
	/// Get and set the city.
	/// </summary>
	public string City
	{
		get 
		{
			return permanentRecord.city;
		}
		set 
		{ 
			permanentRecord.city = value;
		}
	}

	/// <summary>
	/// Get and set the state.
	/// </summary>
	public string State
	{
		get 
		{
			return permanentRecord.state;
		}
		set 
		{ 
			permanentRecord.state = value;
		}
	}

	/// <summary>
	/// Get and set the zip.
	/// </summary>
	public string Zip
	{
		get 
		{
			return permanentRecord.zip;
		}
		set 
		{ 
				permanentRecord.zip = value;
		}
	}
	#endregion
}

C#	Create an AddressList
Listing 2	This is the simplest version of the AddressList. It can be a data source, but the controls can't create columns for it yet.

[DesignerCategoryAttribute("code")]
[ToolboxItem(true)]
[DesignTimeVisible (true)]
public class AddressList : CollectionBase, 
	IComponent
{
	#region IComponent Members

	// Added to implement Site property correctly.
	private ISite _site = null;

	/// <summary>
	/// Notify those that care when we dispose.
	/// </summary>
	public event System.EventHandler Disposed;

	/// <summary>
	/// Get / Set the site where this data is 
	/// located.
	/// </summary>
	public ISite Site
	{
		get
		{
			return _site;
		}
		set
		{
			_site = value;
		}
	}
	#endregion

	#region IDisposable Members
	/// <summary>
	/// Clean up. Nothing here though.
	/// </summary>
	public void Dispose()
	{
	 // Nothing to clean.
	 if (Disposed != null)
		 Disposed (this, EventArgs.Empty);
	}
	#endregion
}

