winform: 设置下拉框数据源的公共函数

本文详细介绍了如何使用 C# 设置 DevExpress ComboBox 控件的下拉框参数,包括查询 SQL、数据源、预设文本和可编辑性设置。
// 设置下拉框 传入参数(需要设置的下拉框控件,查询的语句,默认第一行的内容) public static void SetComboList(DevExpress.XtraEditors.ComboBoxEdit ComboList, string QuerySQL, ArrayList arrSource = null, DataTable dtSource = null, string FirstRowText = "", bool bSelectFirstItem = false, bool bEditable = false) { DataTable dtList = null; if (dtSource != null) { dtList = dtSource; } else if (arrSource != null) { dtList = new DataTable(); dtList.Columns.Add("name"); foreach (string s in arrSource) { dtList.Rows.Add(s); } } else if (!string.IsNullOrEmpty(QuerySQL)) { try { dtList = SqlHelper.ExecuteDataTable(SqlHelper.ConnString, CommandType.Text, QuerySQL, null); } catch (Exception ex) { Common.DisplayMsg("数据访问异常:", ex.Message.ToString()); return; } } else { return; } int intCount = (dtList != null) ? dtList.Rows.Count : 0; if (bEditable) { ComboList.Properties.TextEditStyle = TextEditStyles.Standard; } else { ComboList.Properties.TextEditStyle = TextEditStyles.DisableTextEditor; // 设置 comboBox的文本值不能被编辑 } ComboList.Properties.Items.Clear(); if (!string.IsNullOrEmpty(FirstRowText)) ComboList.Properties.Items.Add(FirstRowText); if (intCount > 0) { for (int i = 0; i < intCount; i++) { ComboList.Properties.Items.Add(dtList.Rows[i][0].ToString()); } } if (bSelectFirstItem) ComboList.SelectedIndex = 0; // 设置选中第1项 }
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值