C# 调整DataGridView列宽
我目前正在尝试在我的C Winforms应用程序中创建DataGridView 我以以下方式添加入口:C# 调整DataGridView列宽,c#,C#,我目前正在尝试在我的C Winforms应用程序中创建DataGridView 我以以下方式添加入口: private void Form1_Load(object sender, EventArgs e) { table.Columns.Add("Username", typeof(string)); table.Columns.Add("Status", typeof(string)); table.Rows.Add("first", "second");
private void Form1_Load(object sender, EventArgs e)
{
table.Columns.Add("Username", typeof(string));
table.Columns.Add("Status", typeof(string));
table.Rows.Add("first", "second");
bunifuCustomDataGrid1.DataSource = table;
}
但是我不能让数据网格的大小达到100%
截图:
我怎样才能让它填满数据网格
bunifuCustomDataGrid1.Columns[1].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill;
查看-您只需要设置要填充的列Autosizemode属性
table.Columns.Add("Username", typeof(string));
table.Columns.Add("Status", typeof(string));
table.Rows.Add("first", "second");
dataGridView1.DataSource = table;
dataGridView1.Columns[0].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill;
dataGridView1.Columns[1].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill;
如果解决了您的问题,请接受其中一个答案。否则,你可以写一条评论来回答并描述为什么它对你没有帮助