- 积分
- 225
- 在线时间
- 134 小时
- 主题
- 23
- 注册时间
- 2013-6-9
- 帖子
- 71
- 最后登录
- 2023-2-9
- 帖子
- 71
- 软币
- 1999
- 在线时间
- 134 小时
- 注册时间
- 2013-6-9
|
本帖最后由 sinomac 于 2013-6-27 00:09 编辑
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)
复制代码- 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)
复制代码
|
评分
-
查看全部评分
|