【问题标题】:Impossible to see data in DataGridView until i click or select cells C#在我单击或选择单元格 C# 之前,无法在 DataGridView 中查看数据
【发布时间】:2019-01-04 21:46:52
【问题描述】:

似乎 DataGridView 中的文本字体与背景颜色相似,因此在单击或选择单元格之前我看不到任何数据。我试图在DefaultCellStyle 中更改颜色,但什么也没发生。我该如何解决?

这是我的DefaultCellStyle 代码:

dataGridViewCellStyle1.BackColor = System.Drawing.SystemColors.Window;
dataGridViewCellStyle1.Font = new System.Drawing.Font("Microsoft Sans Serif", 8.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(204)));
dataGridViewCellStyle1.ForeColor = System.Drawing.Color.Red;
dataGridViewCellStyle1.SelectionBackColor = System.Drawing.SystemColors.Highlight;
dataGridViewCellStyle1.SelectionForeColor = System.Drawing.SystemColors.HighlightText;

应该没问题,就像在这个预览中一样:

但事实并非如此:

【问题讨论】:

  • 前景色是透明的,会影响文字颜色
  • @AleksaRistic 将其更改为红色,我仍然有这个问题。仅在 CellStyle Builder 预览中看起来不错
  • 当你从那个窗口改变它时,检查是否在代码中应用了改变
  • @AleksaRistic 是的,但是当我编译我的程序并运行它时,它会变回透明,但不在设计器代码中,只是在属性中。好奇怪……
  • 好吧,我只是在 form.cs 中以编程方式更改了它

标签: c# database windows winforms


【解决方案1】:

似乎这是 SharpDevelop 中的一个错误。我不确定,但我的朋友在 Visual Studio 中没有遇到任何问题。要解决此问题,只需将此行添加到您的 Form.cs(而不是您的设计器)。

dataGridView.ForeColor = System.Drawing.Color.Black;

【讨论】:

    【解决方案2】:

    在我的情况下,这是因为尝试从另一个线程更新 DGV, 使用调用对我有用。

    this.Invoke(new Action(() =>
     {
    //update DGV 
      }));
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2019-09-30
      • 1970-01-01
      • 1970-01-01
      • 2023-03-24
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-10-25
      相关资源
      最近更新 更多