[英]Dynamic DataGridView creation columns and rows not coming in winform using c#
i am trying to create a 8*8 gridview but the columns & rows aren't coming .. my code is like this .. 我试图创建一个8 * 8网格视图,但列和行都没有来..我的代码是这样的..
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]);
here epnl is a panel. 这里的epnl是一个面板。 i am trying to set the height of every cell as 2 and width as 2 as well but the cells are not coming .. i am only getting an empty datagridview pls help 我试图将每个单元格的高度设置为2,将宽度设置为2,但是单元格不会显示..我只得到一个空的datagridview pls帮助
This is basically because your not adding anything. 这基本上是因为您未添加任何内容。
You need to create Row object :- 您需要创建Row对象:-
DataGridViewRow row = new DataGridViewRow();
for (k = 1; k <= 8; k++)
{
grid[i].Rows.Add(row);
}
I think this should help. 我认为这应该有所帮助。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.