|
using System;
using System.ComponentModel;
using System.Collections;
using System.Diagnostics;
namespace CL.DataBinding
{
/// <summary>
/// This object inherits from Component and thus can be placed on
/// a web form at design time. This class allows us to bind
/// various web controls to our person object
/// </summary>
///
public class PersonAdapter : System.ComponentModel.Component
{
/// <summary>
/// Required designer variable.
/// </summary>
private System.ComponentModel.Container components = null;
public PersonAdapter(System.ComponentModel.IContainer container)
{
///
/// Required for Windows.Forms Class Composition Designer support
///
container.Add(this);
InitializeComponent();
//
// TODO: Add any constructor code after InitializeComponent call
//
}
public PersonAdapter()
{
///
/// Required for Windows.Forms Class Composition Designer support
///
InitializeComponent();
//
// TODO: Add any constructor code after InitializeComponent call
//
}
/// <summary>
/// provides access to our person object so a web form
/// can bind to the person's properties
/// </summary>
private Person person;
public Person Person
{
get
{
return person;
}
set
{
person=value;
}
}
/// <summary>
/// We use this property to bind to one of our control's
/// back color property
/// </summary>
public System.Drawing.Color FavoriteColor
{
get
{
switch (person.FavoriteColor.Color)
{
case "Blue":
return System.Drawing.Color.Blue;
case "Green":
return System.Drawing.Color.Green;
case "Red":
return System.Drawing.Color.Red;
default:
return System.Drawing.Color.Black;
}
}
}
/// <summary>
/// for check box binding
/// </summary>
public bool IsLongName
{
get
{
if (person.Name.Length>10)
return true;
else
return false;
}
}
/// <summary>
/// binds to the text of our 'submit' button
/// </summary>
public string UpdateButtonText
{
get
{
return "Update " + person.Name;
}
}
/// <summary>
/// Clean up any resources being used.
/// </summary>
protected override void Dispose( bool disposing )
{
if( disposing )
{
if(components != null)
{
components.Dispose();
}
}
base.Dispose( disposing );
}
#region Component Designer generated code
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
components = new System.ComponentModel.Container();
}
#endregion
}
}
|
By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.
If a file you wish to view isn't highlighted, and is a text file (not binary), please
let us know and we'll add colourisation support for it.
Chris Lennon lives in Auckland, New Zealand. He is married with two children. He is a software development manager, currently working on a distributed Windows Forms.NET application written in C#.
He is a fan of Extreme Programming (XP) and Rapid Application Development (RAD) methedologies. His interest is in creating a template-driven approach to facilitate the production of high quality windows and web applications, within a short development cycle.
Besides looking after his kids, Chris attends Christian Life Centre Auckland, a vibrant church in the heart of Auckland City.