2017-04-21 128 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 )也起作用!谢谢 –

相关问题