【问题标题】:How to set datagridview's rows/columns width to the datagridview's width?如何将 datagridview 的行/列宽度设置为 datagridview 的宽度?
【发布时间】:2017-04-22 00:14:29
【问题描述】:

对不起,一个简单的问题:

我正在使用此例程将字符串列表显示到 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;

它会像这样显示:

我希望将行的大小调整为我最初在设计器中设置的 datagridview 大小。我该怎么做?

【问题讨论】:

  • 设计师生成的代码是什么?
  • @kennyzx 哦,对,。编辑!谢谢
  • 试试 AutoSizeColumnsMode 填充
  • @kennyzx 工作!谢谢

标签: c# winforms datagridview windows-forms-designer


【解决方案1】:

对于水平拉伸使用这个:

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

对于垂直我认为这是不可能的,最终你可以为每一行设置高度

【讨论】:

  • 正如@kennyzx 的评论,This 也有效!谢谢
猜你喜欢
  • 2010-11-11
  • 1970-01-01
  • 1970-01-01
  • 2011-01-10
  • 2011-04-23
  • 1970-01-01
  • 1970-01-01
  • 2015-07-16
  • 1970-01-01
相关资源
最近更新 更多