如何将一个二维数组的内容显示到一个datagridView里面?

一个二维字符串数组,members[5,4],将其显示到一个dataGridView1中?... 一个二维字符串数组,members[5,4],将其显示到一个dataGridView1中? 展开
 我来答
好奇号1225
2011-05-03 · TA获得超过496个赞
知道答主
回答量:88
采纳率:100%
帮助的人:24.4万
展开全部
建一个DATATABLE,5行4列,给单元格赋值,然后绑定到dataGridView1,就可以了。
或则循环该数组,给dataGridView1赋值。
呵呵,,开玩笑的,你的问题描述的不太清楚,
th79d
推荐于2017-10-08 · TA获得超过265个赞
知道小有建树答主
回答量:203
采纳率:0%
帮助的人:253万
展开全部

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;

}

本回答被提问者采纳
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
百度网友3783cdc
2018-06-22
知道答主
回答量:1
采纳率:0%
帮助的人:837
引用th79d的回答:
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;
}

展开全部
string[] st = new string[4];放错位置了,正确如下:
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;
}
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
收起 1条折叠回答
推荐律师服务: 若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询

为你推荐:

下载百度知道APP,抢鲜体验
使用百度知道APP,立即抢鲜体验。你的手机镜头里或许有别人想知道的答案。
扫描二维码下载
×

类别

我们会通过消息、邮箱等方式尽快将举报结果通知您。

说明

0/200

提交
取消

辅 助

模 式