/// <summary> /// /// </summary> public class ListControlTable : DataTable,System.Collections.IEnumerable { /// <summary> /// /// </summary> public ListControlTable():base("ListControlTable") { this.InitClass(); }
/// <summary>
///
/// </summary>
public DataColumn DisplayColumn
{
get{ return this.Columns["displayColumn"]; }
}
/// <summary>
///
/// </summary>
public DataColumn ValueColumn
{
get{ return this.Columns["valueColumn"]; }
}
/// <summary>
///
/// </summary>
/// <returns></returns>
public System.Collections.IEnumerator GetEnumerator()
{
return this.Rows.GetEnumerator();
}
/// <summary>
///
/// </summary>
/// <returns></returns>
public override DataTable Clone()
{
ListControlTable cln = (ListControlTable)base.Clone();
return cln;
}
/// <summary>
///
/// </summary>
/// <param name="SourceTable"></param>
/// <param name="ValueColumn"></param>
/// <param name="DisplayColumn"></param>
/// <param name="Refill"></param>
/// <param name="InsertNull"></param>
/// <param name="NullText"></param>
public void Fill(DataTable SourceTable,DataColumn ValueColumn,
DataColumn DisplayColumn,bool Refill,bool InsertNull,string NullText)
{
foreach(DataRow row in SourceTable.Rows)
{
object[] rowArray = new object[3];
rowArray[0] = (row.ItemArray[ValueColumn.Ordinal].Equals(DBNull.Value))
? 0 : row.ItemArray[ValueColumn.Ordinal];
rowArray[1] = row.ItemArray[ValueColumn.Ordinal];
rowArray[2] = row.ItemArray[DisplayColumn.Ordinal];
if(!Refill) this.Rows.Add(rowArray);
else
{
this.BeginLoadData();
this.LoadDataRow(rowArray,true);
this.EndLoadData();
}
}
if(InsertNull)
{
DataRow row = this.NewRow();
this.Rows.Add(new object[] {0,DBNull.Value,NullText});
}
this.DefaultView.Sort = "displayColumn";
}
/// <summary>
///
/// </summary>
/// <returns></returns>
protected override DataTable CreateInstance()
{
return new ListControlTable();
}
private void InitClass()
{
this.Columns.Add(new DataColumn("valueColumnKey",typeof(int),
null,System.Data.MappingType.Element));
this.Columns.Add(new DataColumn("valueColumn",typeof(int),
null,System.Data.MappingType.Element));
this.Columns.Add(new DataColumn("displayColumn",typeof(string),
null,System.Data.MappingType.Element));
//This is needed for the DataTable.LoadDataRow() method.
this.PrimaryKey = new DataColumn[] {this.Columns["valueColumnKey"]};
}
}