2017-04-21 126 views
0

對不起,一個簡單的問題:如何將datagridview的行/列寬設置爲datagridview的寬度?

我使用這個程序來顯示字符串列表到一個DataGridView:

List<string> MyDataSource = MyList.Select(x => Path.GetFileNameWithoutExtension(x)).ToList(); 

AllVideosGrid.DataSource = MyDataSource.ConvertAll(x => new { Value = x }); 

設計器生成的代碼:

// MyGrid 
// 
this.AllVideosGrid.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize; 
this.AllVideosGrid.Location = new System.Drawing.Point(33, 185); 
this.AllVideosGrid.Name = "AllVideosGrid"; 
this.AllVideosGrid.RowTemplate.Height = 24; 
this.AllVideosGrid.Size = new System.Drawing.Size(319, 498); 
this.AllVideosGrid.TabIndex = 32; 

而且它還有顯示像這樣:

enter image description here

我想要將行的大小調整爲我在設計器中初始設置的datagridview大小。我怎樣才能做到這一點?

+0

? – kennyzx

+0

@kennyzx哦,對,。編輯!謝謝 –

+1

嘗試AutoSizeColumnsMode填充 – kennyzx

回答

1

的水平strecth使用本:

this.AllVideosGrid.Columns[0].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill; 

對於垂直我認爲這是不可能的,最終你可以設置高度是設計器生成什麼代碼的每一行

+0

作爲@kennyzx的評論,[** This **](http://stackoverflow.com/questions/43547196/how-to-set-datagridviews-rows-size-to-the-datagridviews-size#comment74146793_43547196 )也起作用!謝謝 –

相關問題