[英]DataGridView variable formatting
I have a DataGridView with data I extract from SQL Server
. 我有一个DataGridView,其中包含从SQL Server
提取的数据。 I never know how many records i'll have in it so I need the grid to be variable to the number of rows extracted. 我不知道我将拥有多少条记录,因此我需要将网格可变为提取的行数。
Exemple : 范例:
Also, I would like to remove the empty row that is always added too, adding a new row won't be an option. 另外,我想删除总是添加的空行,添加新行将不是一种选择。
Is that possible ? 那可能吗 ?
You are looking for DataSet.Datatable.Rows.Count
this will tell you the total rows returned from your Sql Server 您正在寻找DataSet.Datatable.Rows.Count
这将告诉您从Sql Server返回的总行
Update this cannot be achieved by using the any properties of the DataGridView Control 更新这不能通过使用DataGridView控件的任何属性来实现
You need to set the AutoSizeColumns
properties: 您需要设置AutoSizeColumns
属性:
datagridview.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.Fill;
datagridview.AutoResizeColumns(DataGridViewAutoSizeColumnsMode.DisplayedCells);
Assuming you're filling the grid from a DataSet
, you can use this to prevent empty rows from being added: 假设您是从DataSet
填充网格,则可以使用它来防止添加空行:
foreach (DataRow row in dataset.Tables[0].Rows)
{
if (!string.IsNullOrWhiteSpace(row[0].ToString()))
{
//add row
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.