【问题标题】:How to format cells inside DataGridView more effectively如何更有效地格式化 DataGridView 中的单元格
【发布时间】:2021-05-03 19:14:32
【问题描述】:

我正在编写 ID3 标记编辑器,并且那里有 DataGridView。我有 ID3 帧 ID(“TIT1”、“TIT2”等),我想显示相应的标签而不是它们(“Title 1”、“Title 2”等)... 所以我使用了 CellFormatting,但我注意到这样的事件被调用的次数比我真正需要的要多得多,这让我的程序变慢了。有没有更好的方法来实现它?我需要在向 DataGridView 添加新行时格式化单元格。

private void dataGridView1_CellFormatting(object sender, DataGridViewCellFormattingEventArgs e)
        {
                    if (known_frameIDs_current.Contains(e.Value))
                    {
                        e.Value = frameID_labels[Array.IndexOf(known_frameIDs_current,e.Value), isEnglish];
                    }
                    e.FormattingApplied = true;
        }

【问题讨论】:

  • DataGridView 有一个 RowsAdded 事件。
  • 别找你了;你是说你有一个DGV,显示一个DataTable,其中的行写着TIT1 TIT2,你想让他们说“Title 1”,“Title 2”?使用字典并替换值..

标签: c# datatable datagridview cell datasource


【解决方案1】:

谢谢。我已经使用 RowsAdded 重写了代码

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-07-11
    • 1970-01-01
    • 1970-01-01
    • 2012-08-04
    • 2011-12-25
    • 2020-12-06
    相关资源
    最近更新 更多