【问题标题】:C# Winform Messy/blurry text in DatagridC# Winform Datagrid 中的凌乱/模糊文本
【发布时间】:2012-10-29 04:32:42
【问题描述】:

我的表单上有一个数据网格,它与 DataTable 绑定 我用这个代码

public void SetDataSource(DataTable dt)
    {            
        dgr.DataSource = null;
        dgr.AutoGenerateColumns = false;            
        dgr.DataSource = dt;                 
    }

每次我单击标题或想要更改组合框时,单元格中的文本看起来都会一次又一次地被覆盖。没见过,看(这是第五次点击标题后)

数据网格是只读的,没有什么特别的设置我试过 刷新方法 更新方法 更新数据表 还有很多其他的东西,但我放弃了.. 任何帮助将不胜感激

谢谢 帕特

 // 
        // dgr
        // 
        this.dgr.AllowUserToAddRows = false;
        this.dgr.AllowUserToDeleteRows = false;
        this.dgr.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom) 
        | System.Windows.Forms.AnchorStyles.Left) 
        | System.Windows.Forms.AnchorStyles.Right)));
        this.dgr.AutoSizeColumnsMode = System.Windows.Forms.DataGridViewAutoSizeColumnsMode.Fill;
        this.dgr.BackgroundColor = System.Drawing.Color.Lavender;
        dataGridViewCellStyle21.Alignment = System.Windows.Forms.DataGridViewContentAlignment.MiddleCenter;
        dataGridViewCellStyle21.BackColor = System.Drawing.SystemColors.Control;
        dataGridViewCellStyle21.Font = new System.Drawing.Font("Microsoft Sans Serif", 8.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
        dataGridViewCellStyle21.ForeColor = System.Drawing.SystemColors.WindowText;
        dataGridViewCellStyle21.SelectionBackColor = System.Drawing.SystemColors.Highlight;
        dataGridViewCellStyle21.SelectionForeColor = System.Drawing.SystemColors.HighlightText;
        dataGridViewCellStyle21.WrapMode = System.Windows.Forms.DataGridViewTriState.True;
        this.dgr.ColumnHeadersDefaultCellStyle = dataGridViewCellStyle21;
        this.dgr.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize;
        this.dgr.Columns.AddRange(new System.Windows.Forms.DataGridViewColumn[] {
        this.Title,
        this.SKU,
        this.Popularity,
        this.Profitability,
        this.Qty,
        this.Score,
        this.EPT,
        this.QPPF,
        this.Overall,
        this.URL});
        this.dgr.EditMode = System.Windows.Forms.DataGridViewEditMode.EditOnEnter;
        this.dgr.Enabled = false;
        this.dgr.Location = new System.Drawing.Point(12, 60);
        this.dgr.MultiSelect = false;
        this.dgr.Name = "dgr";
        this.dgr.RowHeadersWidth = 22;
        dataGridViewCellStyle30.BackColor = System.Drawing.Color.Transparent;
        this.dgr.RowsDefaultCellStyle = dataGridViewCellStyle30;
        this.dgr.Size = new System.Drawing.Size(1292, 500);
        this.dgr.TabIndex = 4;
        this.dgr.CellDoubleClick += new System.Windows.Forms.DataGridViewCellEventHandler(this.dgr_CellDoubleClick);
        this.dgr.CellMouseClick += new System.Windows.Forms.DataGridViewCellMouseEventHandler(this.dgr_CellMouseClick);
        this.dgr.DataBindingComplete += new System.Windows.Forms.DataGridViewBindingCompleteEventHandler(this.dgr_DataBindingComplete);
        this.dgr.MouseMove += new System.Windows.Forms.MouseEventHandler(this.dgr_MouseMove);

【问题讨论】:

  • 这是否是 OwnerDrawn DataGridView。你玩过单元格绘制吗,看起来DataGridView单元格的PaintBackground根本没有被调用。
  • 这是标准网格。我不使用任何绘图事件。我使用这些事件:EditingControlShowing、DataBindingComplete、DataError、MouseMove
  • 您能否再发布一些代码,尤其是在您设置 DataGridView 时
  • 我可以在这里附加附件吗?
  • 我认为你不能,但你可以编辑你的问题,它也将帮助其他人为你找到解决方案。只需粘贴初始化代码。

标签: c# winforms datagrid


【解决方案1】:

我不知道您是如何设法设置此dataGridViewCellStyle30.BackColor = System.Drawing.Color.Transparent; 的,但它会引起您的所有问题,请尝试更改它。它基本上不会重新填充您的背景,并且会在前一个文本上绘制新文本。将其更改为 dataGridViewCellStyle30 中的其他颜色。

【讨论】:

  • 伙计,我欠你一杯啤酒。这正是问题所在(4 天,4 天让我发疯......)如果你来捷克共和国,让我知道,你会免费喝一整晚。非常感谢您
  • 很高兴我能帮上忙。当您尝试为大多数其他属性将此颜色设置为透明时,它不会让您这样做,但我也不知道您可以为样式设置透明颜色;-)。如果你的道路能把你带到这里,你可以成为我在塞尔维亚的追求。顺便提一句。我计划明年和我的妻子去布拉格旅行,为什么不呢,我们可以为 WinForms 干杯:-D
  • 好消息是我也住在布拉格,所以明年见 :-)
  • 你拯救了我的一天!!!以防万一,Alfa 通道设置为 0 的每种颜色都会发生这种情况。
猜你喜欢
  • 2020-02-04
  • 2014-07-11
  • 1970-01-01
  • 1970-01-01
  • 2012-01-03
  • 2019-02-21
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多