错误-以编程方式将行添加到datagridview. [英] Error - Adding rows programmatically to a datagridview.

查看:71
本文介绍了错误-以编程方式将行添加到datagridview.的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

嗨.

我通过三层体系结构从sql数据库中读取学习者列表.

我需要将每个具有参考号(learnerID)的学习者分别添加到datagridview中.如果有更多的学习者,则应将其添加到当前列表中.

我从businessLayer中检索所有学习者并将其放在列表中.然后,我将List转换为数组.

Hi.

Im reading a list of learners from an sql database through 3-tier architecture.

I need to add each learner individually with reference number (learnerID) to a datagridview. If there''s more learners, then it should just add to current list.

I retrieve all learners from the businessLayer and place it in a List. Then i convert the List to an array.

this.dgvLearners.DataSource = Blayer.GetLearners((int)learnerIDgo); 
    //get first learner
foreach (int id in learnerIDS)//reading from array of Lists
{
    learnerIDgo = id;
    this.dgvLearners.Rows.Add(Blayer.GetLearners((int)learnerIDgo));
    //get and add all the additional learners
}



错误-不允许我以编程方式将行添加到datagridview.



Error - Doesn''t allow me to add rows programmatically to a datagridview.

推荐答案

添加行仅在网格不是数据绑定的情况下起作用
add rows work only if the grid is not data bond


在datagrid视图上分配了数据源对象后,该对象就绑定在那里. 您可以稍后绑定它.
声明与Blayer.GetLearners((int)learnerIDgo)对象相同类型的另一个对象应创建一个列表"类型的对象.

然后,您可以添加到该新对象(假设它具有插入/添加方法)
添加完多余的内容后,将其绑定到datagridview.

希望这对您有帮助...
Once you have assigned the datasource object on the datagrid view, it bound there.
You could bind it later.
Declaring another object of the same type as your Blayer.GetLearners((int)learnerIDgo) object should create a "list" type object.

You can then add to that new object (assuming it has an insert/add method on it)
Once you''ve added your extra''s, bind it to the datagridview.

Hope this helps...


这篇关于错误-以编程方式将行添加到datagridview.的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆