[英]ComboBox DataSource C#
I have a DataGridView with some columns, one of them is a DataGridViewTextBoxColumn (x:name = ColumnTypeSpeed). 我有一个带有一些列的DataGridView,其中之一是DataGridViewTextBoxColumn(x:name = ColumnTypeSpeed)。 When I start the program I do the following : 当我启动程序时,请执行以下操作:
ColumnTypeSpeed.DataSource = Enum.GetValues(typeof(BusSpeed));
"BusSpeed" is my enum : “ BusSpeed”是我的列举:
public enum BusSpeed
{
BR_125000 = 125000,
BR_666666 = 666666,
BR_33333 = 33333,
BR_50000 = 50000,
BR_62500 = 62500,
BR_100000 = 100000,
BR_250000 = 250000,
BR_500000 = 500000,
BR_1000000 = 1000000
}
The default item is ever the first in the enum list(BR_125000), How do I select another item as default by code ? 默认项目是枚举列表(BR_125000)中的第一个项目,如何通过代码选择另一个项目作为默认项目?
Just override the DefaultNewRowValue property. 只需覆盖DefaultNewRowValue属性。
public class ExtendedCell : DataGridViewTextBoxCell
{
public ExtendedCell(): base()
{
}
public override object DefaultNewRowValue
{
get
{
return "aaa";
}
}
ExtendedColumn col = new ExtendedColumn();
col.Name = AttendanceType;
dgv1.Columns.Add(col);
Got it from here Set default value of all columns runtime in DataGridView 从这里得到它在DataGridView中设置所有列运行时的默认值
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.