2017-04-18 98 views
1

我的客户在我的软件中报告了图形故障后,我做了一个示例项目,我设法轻松地重现了这个问题。我创建一个形式简单停靠的DataGridView,我用随机数据填充它是这样的: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; 

现在我启动我的程序,这样它的一部分是通过我的任务栏覆盖移动窗口,并使用滚动条。突然,所有的数据都搞砸了:

UPDATE:

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; 
} 

enter image description here

这背后的原因是什么?

+0

上述代码何时运行? – Alex

+0

@Alex它将数据添加到通过设计器停靠在表单上的DataGridView。它发生在窗体的构造函数中。 –

+0

问题是“何时”而不是“为什么”。在这个方法中,当这个方法被调用时。我会把一个断点看看它是否不会多次运行。 – Alex

回答