![](https://iknow-base.cdn.bcebos.com/lxb/notice.png)
如何将一个二维数组的内容显示到一个datagridView里面?
或则循环该数组,给dataGridView1赋值。
呵呵,,开玩笑的,你的问题描述的不太清楚,
private void Form1_Load(object sender, EventArgs e)
{
string[,] array=new string[5,4]; //5行4列二维数组
//对数组赋值示例,以便图形显示,为方便用数字代表字符串,
for (int i = 0; i < 5; i++)
for (int j = 0; j < 4; j++)
array[i, j] = (i * 4 + j).ToString();
List<string[]> str = new List<string[]>(); //声明泛型数组
//将二维数组的内容添加到泛型数组
string[] st = new string[4];
for (int i = 0; i < 5; i++)
{
for (int j = 0; j < 4; j++)
{
st[j] = array[i, j];
}
str.Add(st);
}
//查询
var Query = from s in str
select new
{
第1列 = s[0],
第2列 = s[1],
第3列 = s[2],
第4列 = s[3]
};
this.bindingSource1.DataSource = Query;
this.dataGridView1.DataSource = this.bindingSource1;
}
private void Form1_Load(object sender, EventArgs e)
{
string[,] array=new string[5,4]; //5行4列二维数组
//对数组赋值示例,以便图形显示,为方便用数字代表字符串,
for (int i = 0; i < 5; i++)
for (int j = 0; j < 4; j++)
array[i, j] = (i * 4 + j).ToString();
List<string[]> str = new List<string[]>(); //声明泛型数组
//将二维数组的内容添加到泛型数组
string[] st = new string[4];
for (int i = 0; i < 5; i++)
{
for (int j = 0; j < 4; j++)
{
st[j] = array[i, j];
}
str.Add(st);
}
//查询
var Query = from s in str
select new
{
第1列 = s[0],
第2列 = s[1],
第3列 = s[2],
第4列 = s[3]
};
this.bindingSource1.DataSource = Query;
this.dataGridView1.DataSource = this.bindingSource1;
}
private void Form1_Load(object sender, EventArgs e)
{
string[,] array=new string[5,4]; //5行4列二维数组
//对数组赋值示例,以便图形显示,为方便用数字代表字符串,
for (int i = 0; i < 5; i++)
for (int j = 0; j < 4; j++)
array[i, j] = (i * 4 + j).ToString();
List<string[]> str = new List<string[]>(); //声明泛型数组
//将二维数组的内容添加到泛型数组
for (int i = 0; i < 5; i++)
{
string[] st = new string[4]; //应该放在这里
for (int j = 0; j < 4; j++)
{
st[j] = array[i, j];
}
str.Add(st);
}
//查询
var Query = from s in str
select new
{
第1列 = s[0],
第2列 = s[1],
第3列 = s[2],
第4列 = s[3]
};
this.bindingSource1.DataSource = Query;
this.dataGridView1.DataSource = this.bindingSource1;
}