我正在努力将VirtualMode从DataGridView中删除(它不能正常工作,我决定移到分页的网格视图中),一切都很好。
只有一件事还没有找到。我的数据集有直接从数据库中查询的enums,因此只有英文。我很想把这些数据翻译成de DataGridView。我是否可以调用某个处理程序来转换数据源中的数据?
(在VirtualMode中,我实现了CellValueNeeded,它也处理翻译;当虚拟模式关闭时,这个事件就不再触发了。)
发布于 2015-03-13 13:49:31
我做了这样的事情,在不改变底层数据的情况下,在CellFormatting中处理dataGridView事件。
private void Grid_CellFormatting(object sender, DataGridViewCellFormattingEventArgs e)
{
if (e.ColumnIndex != 2) // enum value column
return;
var grid = (DataGridView)sender;
MyEnum val = (MyEnum)grid[e.ColumnIndex, e.RowIndex].Value;
switch (val)
{
case MyEnum.Val1: e.Value = "Translation1"; break;
case MyEnum.Val2: e.Value = "Translation2"; break;
}
e.FormattingApplied = true;
}这只会在列MyEnum 2的单元格中显示№值的转换。
https://stackoverflow.com/questions/29033554
复制相似问题