C# Winform Datagrid 中文本困惑/模糊

标签 c# winforms datagrid

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

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

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

enter image description here

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

谢谢 帕特

 // 
        // 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);

最佳答案

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

关于C# Winform Datagrid 中文本困惑/模糊,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13298187/

相关文章:

c# - 将具有子对象的对象作为属性绑定(bind)到数据网格

c# - 我应该使用 MKAnnotation、MKAnnotationView 还是 MKPinAnnotation?

C# winform 文本框如何在第二次单击按钮时变为空?

mongodb - NoSQL(例如 MongoDB)能否取代数据网格解决方案,例如甲骨文一致性

c# - 获取当前登录用户的文档文件夹路径

c# - 将处理程序添加到我的组件父窗体的所有控件

c# - 在 WPF DataGrid 中使用 Enter 键作为 Tab

c# - 我不明白为什么我会收到以下错误

c# - VS2010 代码库选项

c# - 如何在C#中编写此Java代码