ComboBox的真实值和显示值
一、類型
/// <summary>
/// 下拉框值類型
/// </summary>
public class TextAndValue
{
/// <summary>
/// 顯示值
/// </summary>
public string DisplayText { get; set; }
/// <summary>
/// 真實值
/// </summary>
public string RealValue { get; set; }
public TextAndValue(string text, string value)
{
DisplayText = text;
RealValue = value;
}
}
二、賦值
#region 車輛用途
ArrayList vehUse = new ArrayList();
vehUse.Add(new TextAndValue("-請選擇-", "-請選擇-"));
vehUse.Add(new TextAndValue("營運車", "0"));
vehUse.Add(new TextAndValue("非營運車", "1"));
comVehUse.DataSource = vehUse;
comVehUse.DisplayMember = "DisplayText";
comVehUse.ValueMember = "RealValue";
#endregion
三、取值
1.真實值:comboBox1.SelectedValue.ToString()===>0和1
2.顯示值:comboBox1.Text;===>營運車和非營運車
轉載于:https://www.cnblogs.com/LeiYang5237/p/8549129.html
總結
以上是生活随笔為你收集整理的ComboBox的真实值和显示值的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 为什么你应该让你的孩子尽早学习编程
- 下一篇: 从运维的角度理解Iaas、Paas、Sa