我的客户在我的软件中报告了一个图形故障后,我做了一个示例项目,我设法轻松地重现了这个问题。我在表单中创建了一个简单的停靠DataGridView,并用随机数据填充它:
var ds = new DataSet();
var table = ds.Tables.Add();
Enumerable.Range(0, 100).ForEach(i => table.Columns.Add(i.ToString()));
Enumerable.Range(0, 100).ForEach(i =>
{
var row = table.NewRow();
Enumerable.Range(0, 100).ForEach(j => row[j.ToString()] = Guid.NewGuid().ToString());
table.Rows.Add(row);
});
dataGridView1.DataSource = table;
现在我启动我的程序,移动窗口,以便我的任务栏覆盖它的一部分并使用滚动条。突然间,所有数据都搞砸了:
更新
partial class Form1
{
/// <summary>
/// Required designer variable.
/// </summary>
private System.ComponentModel.IContainer components = null;
/// <summary>
/// Clean up any resources being used.
/// </summary>
/// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
protected override void Dispose(bool disposing)
{
if (disposing && (components != null))
{
components.Dispose();
}
base.Dispose(disposing);
}
#region Windows Form Designer generated code
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
this.dataGridView1 = new System.Windows.Forms.DataGridView();
((System.ComponentModel.ISupportInitialize)(this.dataGridView1)).BeginInit();
this.SuspendLayout();
//
// dataGridView1
//
this.dataGridView1.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize;
this.dataGridView1.Dock = System.Windows.Forms.DockStyle.Fill;
this.dataGridView1.Location = new System.Drawing.Point(0, 0);
this.dataGridView1.Name = "dataGridView1";
this.dataGridView1.Size = new System.Drawing.Size(986, 758);
this.dataGridView1.TabIndex = 0;
//
// Form1
//
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(986, 758);
this.Controls.Add(this.dataGridView1);
this.Name = "Form1";
this.Text = "Form1";
((System.ComponentModel.ISupportInitialize)(this.dataGridView1)).EndInit();
this.ResumeLayout(false);
}
#endregion
private System.Windows.Forms.DataGridView dataGridView1;
}
这背后的原因是什么?
答案 0 :(得分:1)
因此,作为解决方案,可以使用.Invalidate()
方法。虽然这不是最好的方法。有关invalidate方法的更多信息,请访问:
PushPlugin
答案 1 :(得分:0)
g[x,y].Style.BackColor = Color.Transparent;