在C#中将行添加到绑定的datagridview [英] Adding rows to a bound datagridview in C#

查看:144
本文介绍了在C#中将行添加到绑定的datagridview的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好,有人对单击添加"按钮时向datagridview添加新行有一个想法.如果DGV已被数据绑定,并且包含数据,并且要添加的新空行应显示在最后一行的下方.

Hi do anyone have an idea about adding new rows to datagridview on clicking add button. provided the DGV is already databound and it contains data and the new empty row to be added should display below the last row.

dgv.DataBindings.Clear();
                dgv.AllowUserToAddRows = true;
                int n = dgv.Rows.Add();
                dgv.Rows[n].Cells["col1;].Value = iaccountID;
                dgv.Rows[n].Cells["col2"].Value = iprojectID;
                dgv.Rows[n].Cells["col3"].Value = DBNull.Value;
                dgv.ClearSelection();
                dgv.CurrentCell = dgv.Rows[n].Cells["col1"];
                dgv.BeginEdit(true);



到目前为止,这是我所做的事情,默认情况下,AllowUsersToAddRows属性设置为false.

单击添加按钮时,我将AllowUsersToAddRow属性设置为true

在此先感谢



This is wat I''ve done so far, by default the AllowUsersToAddRows property is set to false.

When clicking add button I''m setting AllowUsersToAddRow property to true

Thanks in Advance

推荐答案

hi

尝试使用此链接

http://social.msdn.microsoft.com /Forums/zh-CN/winformsdatacontrols/thread/afa42681-84db-4e16-93e1-80afe0b1ff5b/ [
hi

try with this link

http://social.msdn.microsoft.com/Forums/en-US/winformsdatacontrols/thread/afa42681-84db-4e16-93e1-80afe0b1ff5b/[^]


这篇关于在C#中将行添加到绑定的datagridview的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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