using System;
using System.Data;
using System.Windows.Forms;
using System.ComponentModel;
namespace AuxiliaryTextBox
...{
/**//// <summary>
/// 扩展的文本框,支持数据表绑定,基于拼音码的辅助输入
/// </summary>
public class AuliaryTextBox : TextBox
...{
字段#region 字段
string Empty = string.Empty;
ListBox popupListBox = null; // 所要用到的列表框
string displayMember; // 显示字段
string valueMember; // 值字段
DataTable valueTable; // 包含全部数据的数据表
Control nextControl; // 下一个焦点的控件
string spellCode;
#endregion
构造器#region 构造器
public AuliaryTextBox()
...{
BackColor = System.Drawing.Color.WhiteSmoke;
Text = Empty;
this.SetStyle( ControlStyles.Opaque, true );
}
#endregion
属性#region 属性
[Category( "JueJue1984" ), Description( " 指定一个辅助输入的ListBox实例,该ListBox将包含所有即将可能被输入的数据." ) ]
public ListBox PopupListBox
...{
get...{ return this.popupListBox; }
set...{ this.popupListBox = value; }
}
[Category( "JueJue1984" ), Description( " 指定一个拼音码字段." ) ]
public string SpellCode
...{
get...{ return this.spellCode; }
set...{ this.spellCode = value; }
}
[Category( "JueJue1984" ), Description( "指定作为ListBox对象项目属性的显示值字段" ) ]
public string DisplayMember
...{
get...{ return this.displayMember; }
set...{ this.displayMember = value; }
}
[Category( "JueJue1984" ), Description( "指定作为ListBox对象项目属性的的实际值字段" ) ]
public string ValueMember
...{
get...{ return this.valueMember; }
set...{ this.valueMember = value; }
}
[Browsable( false ) ]
public DataTable ValueTable
...{
get...{ return this.valueTable; }
set...{ this.valueTable = value; }
}
[Category( "JueJue1984" ), Description( "下一个Tab的控件" ) ]
public Control NextControl
...{
get...{ return this.nextControl; }
set...{ this.nextControl = value; }
}
#endregion
逻辑处理,私有方法#region 逻辑处理,私有方法
设置列表控件的状态(数据由数据表指定)#region 设置列表控件的状态(数据由数据表指定)
/**//// <summary>
///◆设置列表控件的状态(数据由数据表指定)
/// </summary>
/// <param name="lb">▼当前正在操作的列表控件</param>
/// <param name="tb">▼相关的文本框控件</param>
/// <param name="keyInt">▼客户端产生的键值</param>
/// <param name="dt1">▼包含全部数据的数据表</param>
/// <param name="DisplayMember">▼列表控件的显示成员</param>
/// <param name="ValueMember">▼列表控件的值成员</param>
private static void SetListStateDataTable( ListBox lb, System.Windows.Forms.TextBox tb, int keyInt , DataTable dt1, string DisplayMember, string ValueMember, string SpellCode )
...{
string x = tb.Text;
if( x == string.Empty )
...{
lb.Visible = false;
return;
}
else
...{
DataTable dt = dt1.Clone();
dt.Rows.Clear();
//数字或者合法字符
if( keyInt == 8 || keyInt == 32 || (keyInt >= 48 && keyInt <= 122) )
...{
//DataTable dt = CD.PublicMethod.GetNullTable( TableName, DisplayMember, ValueMember );
foreach( DataRow dr in dt1.Select( SpellCode + " like '" + tb.Text + "%'" ) )
...{
dt.Rows.Add( dr.ItemArray );
}
if( keyInt == 32 && x == " " )
...{
dt.Rows.Clear();
dt = dt1;
}
if( dt == null || dt.Rows.Count == 0 )
using System.Data;
using System.Windows.Forms;
using System.ComponentModel;
namespace AuxiliaryTextBox
...{
/**//// <summary>
/// 扩展的文本框,支持数据表绑定,基于拼音码的辅助输入
/// </summary>
public class AuliaryTextBox : TextBox
...{
字段#region 字段
string Empty = string.Empty;
ListBox popupListBox = null; // 所要用到的列表框
string displayMember; // 显示字段
string valueMember; // 值字段
DataTable valueTable; // 包含全部数据的数据表
Control nextControl; // 下一个焦点的控件
string spellCode;
#endregion
构造器#region 构造器
public AuliaryTextBox()
...{
BackColor = System.Drawing.Color.WhiteSmoke;
Text = Empty;
this.SetStyle( ControlStyles.Opaque, true );
}
#endregion
属性#region 属性
[Category( "JueJue1984" ), Description( " 指定一个辅助输入的ListBox实例,该ListBox将包含所有即将可能被输入的数据." ) ]
public ListBox PopupListBox
...{
get...{ return this.popupListBox; }
set...{ this.popupListBox = value; }
}
[Category( "JueJue1984" ), Description( " 指定一个拼音码字段." ) ]
public string SpellCode
...{
get...{ return this.spellCode; }
set...{ this.spellCode = value; }
}
[Category( "JueJue1984" ), Description( "指定作为ListBox对象项目属性的显示值字段" ) ]
public string DisplayMember
...{
get...{ return this.displayMember; }
set...{ this.displayMember = value; }
}
[Category( "JueJue1984" ), Description( "指定作为ListBox对象项目属性的的实际值字段" ) ]
public string ValueMember
...{
get...{ return this.valueMember; }
set...{ this.valueMember = value; }
}
[Browsable( false ) ]
public DataTable ValueTable
...{
get...{ return this.valueTable; }
set...{ this.valueTable = value; }
}
[Category( "JueJue1984" ), Description( "下一个Tab的控件" ) ]
public Control NextControl
...{
get...{ return this.nextControl; }
set...{ this.nextControl = value; }
}
#endregion
逻辑处理,私有方法#region 逻辑处理,私有方法
设置列表控件的状态(数据由数据表指定)#region 设置列表控件的状态(数据由数据表指定)
/**//// <summary>
///◆设置列表控件的状态(数据由数据表指定)
/// </summary>
/// <param name="lb">▼当前正在操作的列表控件</param>
/// <param name="tb">▼相关的文本框控件</param>
/// <param name="keyInt">▼客户端产生的键值</param>
/// <param name="dt1">▼包含全部数据的数据表</param>
/// <param name="DisplayMember">▼列表控件的显示成员</param>
/// <param name="ValueMember">▼列表控件的值成员</param>
private static void SetListStateDataTable( ListBox lb, System.Windows.Forms.TextBox tb, int keyInt , DataTable dt1, string DisplayMember, string ValueMember, string SpellCode )
...{
string x = tb.Text;
if( x == string.Empty )
...{
lb.Visible = false;
return;
}
else
...{
DataTable dt = dt1.Clone();
dt.Rows.Clear();
//数字或者合法字符
if( keyInt == 8 || keyInt == 32 || (keyInt >= 48 && keyInt <= 122) )
...{
//DataTable dt = CD.PublicMethod.GetNullTable( TableName, DisplayMember, ValueMember );
foreach( DataRow dr in dt1.Select( SpellCode + " like '" + tb.Text + "%'" ) )
...{
dt.Rows.Add( dr.ItemArray );
}
if( keyInt == 32 && x == " " )
...{
dt.Rows.Clear();
dt = dt1;
}
if( dt == null || dt.Rows.Count == 0 )