单击按钮控件,以动态生成的形式访问Datagridview控件 [英] Access Datagridview control on click of button control in dynamic generated form

查看:98
本文介绍了单击按钮控件,以动态生成的形式访问Datagridview控件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,

我一直在生成动态表单并添加动态控件及其方法.

我想通过单击具有相同形式的按钮控件来访问Gridview控件.你们能帮我吗?

这是代码:

Hi guys,

I have been generating a dynamic form and adding dynamic controls and it''s methods.

I want to access the Gridview control on click of the button control that are in the same form. Can you guys just help me out?

Here is the code :

//gridview event :
 private void dgvorders_CellContentClick(object sender, DataGridViewCellEventArgs e)
{
   try
   {
                DataGridView mygrid = sender as DataGridView;
   }
   catch(exception ex)
   {}
}

//Button event :

private void btnsubmit_Click(object sender, EventArgs e)
{
Button mybutton = sender as Button;

//Here i want to access the gridview and fetch the selected rows
}


网格控件,按钮控件和表单都在运行时动态生成.

谢谢...:)


Grid control, button control and form all are dynamically generated at runtime.

Thanks... :)

推荐答案

大家好....问题已更改,因为我已经找到了解决方案.

现在我的问题是:

当我从gridview控件中以动态形式选择那些行时,然后单击提交"按钮

我想将这些选定的行添加到父窗体中的另一个gridview中.

这是我尝试过的代码:
hey guys....question changes now as i already found the solution of this.

Now my problem is :

When i select those rows from gridview control in the dynamic form., and click on submit button

I want to add those selected rows to another gridview that is in the parent form.

here is the code i tried :
private void btnsubmit_Click(object sender, EventArgs e)
      {
          try
          {
              for (int i = 0; i < dgvorders.Rows.Count; i++)
              {
                  if (dgvorders.Rows[i].Cells["orderstatus"].Value.ToString() == "True")
                  {
                      masterdatagrid.Rows.Add(dgvorders.Rows[i]);
                  }
                  else { }
              }

          }
          catch (Exception ex)
          {

              MessageBox.Show(ex.Message, "Error on Submit");
          }
          Orders.Close();
      }


它给了我一个例外:

当控件与数据绑定时,不能以编程方式将行添加到DataGridView的行集合中."


帮帮我...:confused:

阿舒托什·贾因(Ashutosh Jain).


it gives me the exception:

" Rows cannot be programmatically added to the DataGridView''s rows collection when the control is data-bound."


Help me out guys... :confused:

Ashutosh Jain.


这篇关于单击按钮控件,以动态生成的形式访问Datagridview控件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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