Click here to Skip to main content
15,890,123 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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 :
C#
//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... :)
Posted
Updated 25-Oct-10 20:03pm
v2
Comments
Sandeep Mewara 26-Oct-10 2:04am    
Use PRE tags to format your code part. It makes the question readable.

1 solution

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();
      }

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.
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900