DEV CheckedListBoxControl组件绑定数据源
DEV CheckedListBoxControl组件绑定数据源
C# Code:
private DataTable ColorData
{
get
{
DataTable dtColor = new DataTable();
dtColor.Columns.Add("ColorCode", typeof(string));
dtColor.Columns.Add("ColorName", typeof(string));
dtColor.Columns.Add("ColorType", typeof(string));
dtColor.Rows.Add(new object[] { "Red", "红色", "Color1" });
dtColor.Rows.Add(new object[] { "Green", "绿色", "Color1" });
dtColor.Rows.Add(new object[] { "Blue", "蓝色", "Color3" });
dtColor.AcceptChanges();
return dtColor;
}
}
//来源:C/S框架网(www.csframework.com) QQ:1980854898
private DataTable ColorData
{
get
{
DataTable dtColor = new DataTable();
dtColor.Columns.Add("ColorCode", typeof(string));
dtColor.Columns.Add("ColorName", typeof(string));
dtColor.Columns.Add("ColorType", typeof(string));
dtColor.Rows.Add(new object[] { "Red", "红色", "Color1" });
dtColor.Rows.Add(new object[] { "Green", "绿色", "Color1" });
dtColor.Rows.Add(new object[] { "Blue", "蓝色", "Color3" });
dtColor.AcceptChanges();
return dtColor;
}
}
//来源:C/S框架网(www.csframework.com) QQ:1980854898
C# Code:
private void simpleButton1_Click(object sender, EventArgs e)
{
//绑定数据源显示编号
checkedListBoxControl1.DataSource = this.ColorData;
checkedListBoxControl1.DisplayMember = "ColorCode";
checkedListBoxControl1.ValueMember = "ColorCode";
}
private void simpleButton2_Click(object sender, EventArgs e)
{
//绑定数据源显示名称
checkedListBoxControl2.DataSource = this.ColorData;
checkedListBoxControl2.DisplayMember = "ColorName";
checkedListBoxControl2.ValueMember = "ColorCode";
}
private void simpleButton3_Click(object sender, EventArgs e)
{
ShowItemValues(checkedListBoxControl1); //显示勾选的值
}
private void simpleButton4_Click(object sender, EventArgs e)
{
ShowItemValues(checkedListBoxControl2);//显示勾选的值
}
private void ShowItemValues(DevExpress.XtraEditors.CheckedListBoxControl checkedListBoxControl)
{
StringBuilder sb = new StringBuilder();
foreach (object item in checkedListBoxControl.CheckedItems)
{
DataRowView rv = item as DataRowView; //数据源是DataTable,对应的Item是DataRowView类型。
sb.AppendLine(rv.Row["ColorCode"].ToString());
}
MessageBox.Show("您选择的项目是:\r\n" sb.ToString());
}
//来源:C/S框架网(www.csframework.com) QQ:1980854898
private void simpleButton1_Click(object sender, EventArgs e)
{
//绑定数据源显示编号
checkedListBoxControl1.DataSource = this.ColorData;
checkedListBoxControl1.DisplayMember = "ColorCode";
checkedListBoxControl1.ValueMember = "ColorCode";
}
private void simpleButton2_Click(object sender, EventArgs e)
{
//绑定数据源显示名称
checkedListBoxControl2.DataSource = this.ColorData;
checkedListBoxControl2.DisplayMember = "ColorName";
checkedListBoxControl2.ValueMember = "ColorCode";
}
private void simpleButton3_Click(object sender, EventArgs e)
{
ShowItemValues(checkedListBoxControl1); //显示勾选的值
}
private void simpleButton4_Click(object sender, EventArgs e)
{
ShowItemValues(checkedListBoxControl2);//显示勾选的值
}
private void ShowItemValues(DevExpress.XtraEditors.CheckedListBoxControl checkedListBoxControl)
{
StringBuilder sb = new StringBuilder();
foreach (object item in checkedListBoxControl.CheckedItems)
{
DataRowView rv = item as DataRowView; //数据源是DataTable,对应的Item是DataRowView类型。
sb.AppendLine(rv.Row["ColorCode"].ToString());
}
MessageBox.Show("您选择的项目是:\r\n" sb.ToString());
}
//来源:C/S框架网(www.csframework.com) QQ:1980854898
版权声明:本文为开发框架文库发布内容,转载请附上原文出处连接
NewDoc C/S框架网