以编程方式添加新行 [英] add new row programmatically

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

问题描述

我有一个datagridview和两个按钮.现在我要做的是分别添加新的空白行和分别使用添加​​和删除按钮删除选定的行.

请帮助我
在此先感谢

解决方案

查看以下代码:

要将新行添加到DataGridView中:

 私有 无效 AddButton_Click(对象发​​件人,EventArgs e)
    {
      // 在DataGridView中添加新行
       .dataGridView1.Rows.Add(" " " 七个" 八个") ;
      // 在DataGridView中的0位置添加新行
       .dataGridView1.Rows.Insert( 0 " 一个" 两个"" " 四个");
    } 


要将新行添加到DataGridView中:

 私有  void  DeleteButton_Click(对象发​​件人,EventArgs e)
    {
      .dataGridView1.Rows.RemoveAt( .dataGridView1.CurrentRow.Index);
    } 


希望它会为您提供帮助. void deleteButton_Click(对象发​​件人,EventArgs e) { 尝试 { dataGridViewTrial.Rows.RemoveAt(dataGridViewTrial.CurrentRow.Index); sqlDataAdapter.Update(dataTable); } 捕获(异常exceptionObj) { MessageBox.Show(exceptionObj.Message.ToString()); } }



可以按照以下链接在dataridview中添加行

单击此处 [ ^ ]
如果解决了您的问题,则标记为解决方案


通过此链接,它可以正常工作

链接


i have a datagridview and two buttons. now what i have to do is i have to add new blank row and delete selected row using add and delete button respectively.

plz heplp me out
thanks in advance

解决方案

Check Out the following Code :

To add New Row into DataGridView :

private void AddButton_Click(object sender, EventArgs e)
    {
      //To Add New Row in DataGridView
      this.dataGridView1.Rows.Add("five", "six", "seven", "eight");
      //To Add New Row in DataGridView at 0 position
      this.dataGridView1.Rows.Insert(0, "one", "two", "three", "four");
    }


To add New Row into DataGridView :

private void DeleteButton_Click(object sender, EventArgs e)
    {
     this.dataGridView1.Rows.RemoveAt(this.dataGridView1.CurrentRow.Index);
    }


Ihope it will help you.


private void deleteButton_Click(object sender, EventArgs e)
        {
            try
            {
               dataGridViewTrial.Rows.RemoveAt(dataGridViewTrial.CurrentRow.Index);
               sqlDataAdapter.Update(dataTable);
            }
            catch (Exception exceptionObj)
            {
               MessageBox.Show(exceptionObj.Message.ToString());
            }
        }



can follow below link to add row in dataridview

click here[^]
Mark as solution if its solved your problem


Go thru this link,it works

Link


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

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