由网友(预熟友)分享简介:我如何去展示一个二维整数数组到一个DataGridView控制在C#.net 4.0?How would I go about displaying a 2-dimensional integer array into a DataGridView Control in C# .Net 4.0?推荐答案按照cod...
我如何去展示一个二维整数数组到一个DataGridView控制在C#.net 4.0?
How would I go about displaying a 2-dimensional integer array into a DataGridView Control in C# .Net 4.0?
推荐答案
按照code样品此页面上填充行
属性:
Follow the code sample on this page to populate the Rows
property:
http://msdn.microsoft.com/en-us/library/system.windows.forms.datagridview.aspx
修改
原来,这比我想象的有点棘手。这里有一个code例如:
Turns out this is a bit thornier than I thought. Here's a code example:
var data = new int[4,3]
{
{ 1, 2, 3, },
{ 4, 5, 6, },
{ 7, 8, 9, },
{ 10, 11, 12 },
};
var rowCount = data.GetLength(0);
var rowLength = data.GetLength(1);
for (int rowIndex = 0; rowIndex < rowCount; ++rowIndex)
{
var row = new DataGridViewRow();
for(int columnIndex = 0; columnIndex < rowLength; ++columnIndex)
{
row.Cells.Add(new DataGridViewTextBoxCell()
{
Value = data[rowIndex, columnIndex]
});
}
dataGridView1.Rows.Add(row);
}
相关推荐
最新文章