下拉列表中实现绑定多个数据字段(完整版)
点击下拉列表时,实现在下拉列表中显示多个数据表字段的代码,MutilColumnCombobox
// Most of the important code for this control was
// taken from a control written by Nishant Sivakumar.
// http://doc.guandang.net/cs/combobox/DotNetMultiColumnComboBox.asp
//
// Bugfixes or Suggestions can be sent to dcaillouet@http://doc.guandang.net
//显示多列combobox,设置AutoComplete=true;AutoDropDown=true;
using System;
using System.Windows.Forms;
using System.Collections;
using System.Collections.ObjectModel;
using http://doc.guandang.netponentModel;
using System.Drawing;
using System.Globalization;
namespace MultiColumnComboBoxDemo
{
public class MultiColumnComboBox : ComboBox
{
private bool _AutoComplete;
private bool _AutoDropdown;
private Color _BackColorEven = Color.White;
private Color _BackColorOdd = Color.White;
private string _ColumnNameString = "";
private int _ColumnWidthDefault = 75;
private string _ColumnWidthString = "";
private int _LinkedColumnIndex;
private TextBox _LinkedTextBox;
private int _TotalWidth = 0;
private int _ValueMemberColumnIndex = 0;
private Collection<string> _ColumnNames = new Collection<string>();
private Collection<int> _ColumnWidths = new Collection<int>();
public MultiColumnComboBox()
{
DrawMode = DrawMode.OwnerDrawVariable;
// If all of your boxes will be RightToLeft, uncomment
// the following line to make RTL the default.
//RightToLeft = RightToLeft.Yes;
// Remove the Context Menu to disable pasting
ContextMenu = new ContextMenu();
}
public event System.EventHandler OpenSearchForm;
public bool AutoComplete
{
get
{
return _AutoComplete;
}
set
{
_AutoComplete = value;
}
}
public bool AutoDropdown
{
get
{
return _AutoDropdown;
}
set
{
_AutoDropdown = value;
}
}
public Color BackColorEven
{
get
{
return _BackColorEven;
}
set
{
_BackColorEven = value;
}
}
public Color BackColorOdd
{
get
{
return _BackColorOdd;
}
set
{
_BackColorOdd = value;
}
}
public Collection<string>
ColumnNameCollection
{
get
{
return _ColumnNames;
}
}
public string ColumnNames
{
get
{
return _ColumnNameString;
}
set
{
//
点击下拉列表时,实现在下拉列表中显示多个数据表字段的代码,MutilColumnCombobox
If the column string is blank, leave it blank.
// The default width will be used for all columns.
if (!Convert.ToBoolean(value.Trim().Length))
{
_ColumnNameString = "";
}
else if (value != null)
{
char[] delimiterChars = { ',', ';', ':' };
string[] columnNames = value.Split(delimiterChars);
if (!DesignMode)
{
_ColumnNames.Clear();
}
// After splitting the string into an array, iterate
// through the strings and check that they're all valid.
foreach (string s in columnNames)
{
// Does it have length?
if (Convert.ToBoolean(s.Trim().Length))
{
if (!DesignMode)
{
_ColumnNames.Add(s.Trim());
}
}
else // The value is blank
{
throw new NotSupportedException("Column names can not be blank.");
}
}
_ColumnNameString = value;
}
}
}
public Collection<int> ColumnWidthCollection
{
get
{
return _ColumnWidths;
}
}
public int ColumnWidthDefault
{
get
{
return _ColumnWidthDefault;
}
set
{
_ColumnWidthDefault = value;
}
}
public string ColumnWidths
{
get
{
return _ColumnWidthString;
}
set
{
// If the column string is blank, leave it blank.
// The default width will be used for all columns.
if (!Convert.ToBoolean(value.Trim().Length))
{
_ColumnWidthString = "";
}
else if (value != null)
{
char[] delimiterChars = { ',', ';', ':' };
string[] columnWidths = value.Split(delimiterChars);
string invalidValue = "";
int invalidIndex = -1;
int idx = 1;
int intValue;
// After splitting the str
ing into an array, iterate
// through the strings and check that they're all integers
// or blanks
foreach (string s in columnWidths)
{
//
点击下拉列表时,实现在下拉列表中显示多个数据表字段的代码,MutilColumnCombobox
If it has length, test if it's an integer
if (Convert.ToBoolean(s.Trim().Length))
{
// It's not an integer. Flag the offending value.
if (!int.TryParse(s, out intValue))
{
invalidIndex = idx;
invalidValue = s;
}
else // The value was okay. Increment the item index.
{
idx++;
}
}
else // The value is a space. Use the default width.
{
idx++;
}
}
// If an invalid value was found, raise an exception.
if (invalidIndex > -1)
{
string errMsg;
errMsg = "Invalid column width '" + invalidValue + "' located at column " + invalidIndex.ToString();
throw new ArgumentOutOfRangeException(errMsg);
}
else // The string is fine
{
_ColumnWidthString = value;
// Only set the values of the collections at runtime.
// Setting them at design time doesn't accomplish
// anything and causes errors since the collections
// don't exist at design time.
if (!DesignMode)
{
_
…… 此处隐藏:12003字,全部文档内容请下载后查看。喜欢就下载吧 ……
相关推荐:
- [政务民生]2013年公共基础知识热点问题(七)
- [政务民生]检验检测机构资质认定评审准则及释义20
- [政务民生]关于印发重庆市房屋建筑和市政基础设施
- [政务民生]1、隧道洞身开挖支护施工技术交底书
- [政务民生]2015年山东省17地市中考语文试题分类汇
- [政务民生]2-高级会计师资格考试和评审流程图
- [政务民生]2018版中国清分机行业发展分析及前景策
- [政务民生]新课改高中政治探究
- [政务民生]2018-2024年中国新型组合房屋行业投资
- [政务民生]2015年上海市春季高考数学模拟试卷五
- [政务民生]灌砂法及环刀法测压实度(带计算过程)
- [政务民生]运筹学实验2求解非线性规划
- [政务民生]劝学、逍遥游默写(教师卷)
- [政务民生]《运筹学》 - 期末考试 - 试卷A - 答案
- [政务民生]八年级英语下册 Module 6 Hobbies测试
- [政务民生]2019年宪法知识竞赛试题库100题(含答
- [政务民生]自动化英文文献翻译
- [政务民生]公文格式实施细则
- [政务民生]高一地理上册课堂跟踪练习题6
- [政务民生]会计继续教育习题及答案
- 第三章 无约束最优化方法
- 泛读教程第三册答案
- 魏晋南北朝文学
- 幂的运算复习题
- 城市环境问题的成因与治理策略_以社会
- 钢结构行业产业链及竞争分析研究
- 新型热塑性弹性体增韧聚丙烯的研究
- 中国旅游地理B卷试题及答案
- (苏教版)五年级数学上册第三单元测试卷
- 不稳定性心绞痛诊断与治疗
- 俞氏国际后勤职能部门绩效考核办法
- GB7258-2017新标准考试题含答案
- 小学生汉字听写比赛活动方案
- 1.3《平抛运动》学案 教科版必修2
- 2011香港特别行政区公务员考试复习资料
- 考虑水力条件变化的城市给水管网可靠性
- 表面活性剂在油田开发和生产中的应用
- ITT内部培训资料-FI端吸泵的介绍
- 文明守纪,从我做起学生发言稿
- 初中读《聊斋志异》心得体会800字范文




