2016-08-09 2 views
0

C#Windowsアプリケーションでgridviewを使用しています。セルの1つに長い文字列があります(下記参照)が、グリッドにバインドされるとセルが切り取られ、スクロールバーdoes not get to end of the gridがフルテキストを表示します。マウスでドラッグすると、スクロールバーがスムーズにスクロールしません。C#gridviewウィンドウでテキストが切り取られる

RowSizeとColumnSizeモードでは異なる組み合わせを試しましたが、運がありません。私が集めることができるものから、

void FillGrid() 
{ 
    DataTable tasktable = new DataTable(); 
    tasktable.Columns.Add("Logged By", typeof(string)); 
    tasktable.Columns.Add("Date", typeof(DateTime)); 
    tasktable.Columns.Add("Notes", typeof(string)); 
    DataRow dr1; 
    //for (int i = 0; i < 100; i++) 
    //{ 
    dr1 = tasktable.NewRow(); 
    dr1[0] = "Sunit Shah"; 
    dr1[1] = System.DateTime.Now; 
    dr1[2] = "Test Note"; 
    tasktable.Rows.Add(dr1); 
    //} 
    dr1 = tasktable.NewRow(); 
    dr1[0] = "Sunit Shah"; 
    dr1[1] = System.DateTime.Now; 
    dr1[2] = "Test Note"; 
    dr1[2] = "Paul Pogba will have a medical at Manchester United on Monday after 
      Juventus granted permission for him to seal a potential world record 
      transfer.Juventus manager Massimo Allegri refused to be drawn further 
      on the transfer when he was asked about it in his post-match press 
      conference following a friendly against West Ham at the London Stadium, 
      but an official at the Italian club confirmed they had authorised the 
      midfielder to have United doctors assess him ahead of the move. 
      Allegri merely said: ‘I spoke about Pogba the day before, we have 
      just finished a match and I don’t know much more, we will see on Monday 
      if he is a still Juventus player.’"; 

    tasktable.Rows.Add(dr1); 
    DataTable fillNotesGrid = new DataTable(); 
    fillNotesGrid = (from row in tasktable.AsEnumerable() 
        orderby row.Field<DateTime>("Date") descending 
        select row).CopyToDataTable(); 
    dgvSIDetailsNotes.DataSource = fillNotesGrid;  
} 
+0

グリッドの表示に使用しているコードを投稿できますか? – Interminable

+0

私はちょうど今追加した – Hemil

+0

私は最初にグリッドビューで上記のテキストを表示する理由を考えるだろう。別の行を選択したときに変更される独自のテキストボックスで、グリッド外に表示する方がよい場合があります。 – Takarii

答えて

0

、それはあなたの問題は、それがデータを切り捨てだということではないように、それはあなたがスクロールするとき、それは、細胞へのスナップだということですので、あなたがスクロールするとき、それは右のすべてのセルの上部にあります見えます。利用可能なスペースが大きすぎると、その行の最上部の部分だけが表示されます。基本的には、Microsoft Excelのように動作します。

標準のDataGridViewコントロールでこの動作をオフにする方法はありません。

回避方法として、DataGridViewSystem.Windows.Forms.Panelに追加し、Panelをスクロールさせることができます。

単にDataGridViewPanelコントロールの子を作り、そしてtruePanel "trueへのAutoScroll財産とDataGridViewAutoSizeプロパティを設定し、それはトリックを行う必要があります。

EDIT

私が試してみて、物事を明確にするために、いくつかのソースコードが含まれています。

これは、(本体がFillGrid()の)形式のソースコードで、質問のソースコードと同じですので省略しています)。

public partial class Form1 : Form 
{ 
    public Form1() 
    { 
     InitializeComponent(); 

     dataGridView1.DefaultCellStyle.WrapMode = DataGridViewTriState.True; //I'm assuming this is already set in your own source code as the cell is wrapping its text in your screenshot. 
     panel1.AutoScroll = true; 
     dataGridView1.AutoSize = true; 

     FillGrid(); 
    } 

    void FillGrid() 
    { 
     ... 
    } 
} 

これは、コントロールがForm1.Designer.csで作成されている方法です。

private System.Windows.Forms.DataGridView dataGridView1; 
private System.Windows.Forms.Panel panel1; 

これはデザイナーで生成されたInitializeComponent()方法です。

private void InitializeComponent() 
    { 
     this.dataGridView1 = new System.Windows.Forms.DataGridView(); 
     this.panel1 = new System.Windows.Forms.Panel(); 
     ((System.ComponentModel.ISupportInitialize)(this.dataGridView1)).BeginInit(); 
     this.panel1.SuspendLayout(); 
     this.SuspendLayout(); 
     // 
     // dataGridView1 
     // 
     this.dataGridView1.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize; 
     this.dataGridView1.Location = new System.Drawing.Point(3, 3); 
     this.dataGridView1.Name = "dataGridView1"; 
     this.dataGridView1.Size = new System.Drawing.Size(145, 122); 
     this.dataGridView1.TabIndex = 0; 
     // 
     // panel1 
     // 
     this.panel1.Controls.Add(this.dataGridView1); 
     this.panel1.Location = new System.Drawing.Point(12, 12); 
     this.panel1.Name = "panel1"; 
     this.panel1.Size = new System.Drawing.Size(260, 126); 
     this.panel1.TabIndex = 1; 
     // 
     // Form1 
     // 
     this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F); 
     this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; 
     this.ClientSize = new System.Drawing.Size(284, 261); 
     this.Controls.Add(this.panel1); 
     this.Name = "Form1"; 
     this.Text = "Form1"; 
     ((System.ComponentModel.ISupportInitialize)(this.dataGridView1)).EndInit(); 
     this.panel1.ResumeLayout(false); 
     this.ResumeLayout(false); 

    } 

これはテストプロジェクトでこのソリューションを複製するために必要なすべてのものです。

メインプロジェクトでこの問題が発生している場合は、他のコードが干渉している可能性があります。

+0

私たちはそれを試しました。しかし、それは動作していません。 パネルを追加し、そのAutoScrollプロパティをTrueにしました。 Kept Data GridviewスクロールバーをNoneに設定 実行時にAutosizeをtrueに保ちました。 同じ動作です。私が間違っていることがわからない – Hemil

+0

@Hemil Answerを更新して、あなたに役立ついくつかのソースコードを追加しました。問題が引き続き発生する場合は、自分が行っていること、自分がやっていることなどについて詳細な情報を提供する必要があります。 – Interminable

関連する問題