我正在尝试创建一个8 * 8 gridview但是列和&行没有来..我的代码是这样的..
public static DataGridView[] grid = new DataGridView[30];
public DataGridViewImageColumn col;
grid[i] = new DataGridView();
grid[i].Visible = true;
grid[i].AllowUserToAddRows = false;
grid[i].AllowUserToDeleteRows = false;
grid[i].AllowUserToOrderColumns = false;
grid[i].AllowUserToResizeRows = false;
grid[i].AllowUserToResizeColumns = false;
grid[i].ColumnHeadersVisible = false;
grid[i].RowHeadersVisible = false;
grid[i].Location = new System.Drawing.Point(120,5);
grid[i].Size = new System.Drawing.Size(128, 128);
grid[i].BackgroundColor = Color.SeaShell;
grid[i].GridColor = Color.Green;
grid[i].ClipboardCopyMode = DataGridViewClipboardCopyMode.EnableWithoutHeaderText;
grid[i].CellBorderStyle = DataGridViewCellBorderStyle.Single;
for (j = 1; j <= 8; j++)
{
col = new DataGridViewImageColumn();
col.Width = 2;
col.ImageLayout = DataGridViewImageCellLayout.Normal;
grid[i].Columns.Add(col);
}
for (k = 1; k <= 8; k++)
{
grid[i].Rows.Add();
}
epnl[i].Controls.Add(grid[i]);
这里epnl是一个小组。我试图将每个单元格的高度设置为2,宽度也设置为2,但单元格不会出现..我只是得到一个空的datagridview请帮助
答案 0 :(得分:0)
这基本上是因为你没有添加任何内容。
您需要创建Row对象: -
DataGridViewRow row = new DataGridViewRow();
for (k = 1; k <= 8; k++)
{
grid[i].Rows.Add(row);
}
我认为这应该会有所帮助。