![](/img/trans.png)
[英]How to add a value in the cells of a specific column in a datagridview in c#.net?
[英]how to add data to a specific range of cells in column
關於如何將數據添加到datagridview列中特定范圍的單元格的任何示例。 例如,我希望在第10行和第15行之間的第5列為FALSE。 現在,我的列綁定到數據表,並且所有行都設置為true。
非常感謝
您只需要修改綁定到datagridview的數據表。 這樣的事情應該起作用:
// Setup table with 5 columns
DataTable table = new DataTable();
table.Columns.Add("A", typeof(bool));
table.Columns.Add("B", typeof(bool));
table.Columns.Add("C", typeof(bool));
table.Columns.Add("D", typeof(bool));
table.Columns.Add("E", typeof(bool));
// Add 20 rows
for (int i = 0; i < 20; i++ )
table.Rows.Add(true, true, true, true, true);
// Rows 10 - 15, set column 5 to true
for (int i = 9; i < 15; i++)
table.Rows[i].SetField<bool>(4, false);
注意:列和行索引從零開始,因此行10位於索引9,列5位於索引4,依此類推。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.