2

フォームに1つのデータグリッドがあり、DataTableにバインドされています。このコードを使用します

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

ヘッダーをクリックするか、コンボボックスを変更したいときはいつでも、セル内のテキストが何度も上書きされているように見えます。これまでに見たことがない、見てください(これはヘッダーを5回クリックした後です)

ここに画像の説明を入力してください

datagridは読み取り専用で、特別な設定はありません。RefreshメソッドUpdateメソッドUpdate datatableや他の多くのことを試しましたが、あきらめました。

ありがとうパット

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

1 に答える 1

2

どうやってこれを設定したのかわかりませんが dataGridViewCellStyle30.BackColor = System.Drawing.Color.Transparent;、すべての問題が発生しているので、変更してみてください。基本的に背景を塗り替えることはなく、前のテキストの上に新しいテキストが描画されます。これをdataGridViewCellStyle30の他の色に変更します。

于 2012-11-08T22:53:32.123 に答える