简体   繁体   中英

how to add data to a specific range of cells in column

any example on how to add data to a specific range of cells in datagridview column. for example, i want at column 5 between row 10 and 15 to be FALSE. right now my columns a bind to a datatable and all rows are set to true.
Thanks a lot

You just need to modify the datatable that is bound to the datagridview. Something like this should work:

// 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);

Note: Column and Row indexes are zero-based so Row 10 is at index 9, Column 5 is at index 4, etc.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM