In C# Winforms, I’d like to use a DataGridView as a simple widget to store information to display to the user. To this end, I’d like to create a table of say, 5×10 cells.
After some research, solutions tend to allow adding just one row or column at a time. I’d like the whole grid created initially and straight away, so I can start populating it with data, like you would with a standard C# 2D array.
What’s the simplest way of going about this? A function header could look like this:
createCells(DataGridView dgv, int cols, int rows) {}
It should be quick and amenable to changing the cols and rows to a larger or smaller number later on if need be.
By the way, there might an error like:
To avoid it, set
AutoGenerateColumnsproperty tofalse, and setFillWeightto1for each column generated: