我正在使用devexpress gridview进行车辆管理程序,并得到一个列,显示该行的数据是否被标记为已删除。在数据库中,它们标记为“1”表示活动,“11”表示已删除,因此我创建了一个枚举类:
public enum enmSystemstatus
{
Created = 1,
Deleted = 11
}
这个事件用grid中的单词而不是数字标记它们:
private void gridView1_CustomColumnDisplayText(object sender, CustomColumnDisplayTextEventArgs e)
{
if (e.Column == colVehicle_Systemstatus && e.Value != null)
{
e.DisplayText = (int)e.Value == (int)enmSystemstatus.Created ? "Active" : "Deleted";
}
}
但是该程序也应该可以使用自动过滤行,但是如果我在systemstatus列的搜索框中输入一个字母,程序就会崩溃,因为无法转换这些值来调用异常:
“system.invalidcastexception指定的强制转换无效。”
这可能是因为数据库上的列是整数列,但将其更改为varchar不会影响某些内容
有人为此解决了吗?
提前致谢
DevExpress组件(例如GridControl)支持the wide range of annotation attributes,它允许您有效地将数据库中的整数值映射到特定的枚举成员,并为每个枚举成员提供有意义且可本地化的描述:
public enum DisplayStatus {
[Display(Name = "ACTIVE")]
Active= 1,
[Display(Name = "DELETED")]
Deleted = 11
}
public class Vehicle_DTO {
[EnumDataType(typeof(DisplayStatus))]
[Display(Name = "STATUS")]
public int Status { get; set; }
}
// ...
gridControl1.DataSource = new List<Vehicle_DTO> {
new Vehicle_DTO() { Status = 1 },
new Vehicle_DTO() { Status = 11 },
new Vehicle_DTO() { Status = 11 },
};