寻找一种在整数列上自动过滤字符串的方法

Searching for a way to autofilter strings on an integer column

我正在将 devexpress gridview 用于车辆管理程序,并得到一列显示该行的数据是否被标记为已删除。在数据库中,它们被标记为“1”表示活动,“11”表示已删除,所以我创建了一个枚举 class:

public enum enmSystemstatus
{
    Created = 1, 
    Deleted = 11
}

这个事件用一个词而不是网格视图中的数字来标记它们:

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";
        }
    }

但是程序也应该可以使用自动筛选行,但是如果我在系统状态列的搜索框中输入一个字母,程序就会崩溃,因为无法转换这些值,调用异常:

"system.invalidcastexception specified cast is not valid."

这可能是因为数据库中的列是整数列,但将其更改为 varchar 并没有影响

有人解决这个问题吗?

提前致谢

DevExpress 组件(例如 GridControl) supports 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 },
};

此自定义将应用于所有 UI 元素,包括过滤器 ,无需任何事件处理 和错误: