Click here to Skip to main content
15,885,953 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
ON a win form I have add a Row in data grid. Row include one combo box then text box then again textbox and a button. now i want to add another row (same as above) on the button click event. how can i do this
Posted
Updated 25-Oct-13 1:35am
v2
Comments
Thanks7872 25-Oct-13 7:26am    
C# is not enough to answer your question.Tag the question properly.
Muhamad Faizan Khan 25-Oct-13 7:35am    
what i need to add more?

what you want exactly can you explain a bit more please :(
 
Share this answer
 
Comments
VICK 28-Oct-13 0:47am    
to post a comment or to ask any question. Kindly use "Have a Question or Comment" option.
C#
private void dataGridView1_CellContentClick(object sender, DataGridViewCellEventArgs e)
        {
              if (e.RowIndex >= 0 && ((DataGridView)sender).Columns[e.ColumnIndex].GetType() == typeof(DataGridViewButtonColumn))
              {
                  DataGridViewRow row = (DataGridViewRow)dataGridView1.Rows[0].Clone();
                  dataGridView1.Rows.Add(row);

                 // MessageBox.Show(e.ColumnIndex.ToString()+' '+e.RowIndex);
               }
             ///
              
                  //ComboColumn.DisplayMember = "Column Name";
 
 


        }
 
Share this answer
 
Comments
Muhamad Faizan Khan 28-Oct-13 0:56am    
it is working but the problem is;
it is working on both button click plus when i select any option in combobox or i write in textbox it also get fire
VICK 28-Oct-13 1:01am    
Because you are doing in CellContentClick so it will be called on click on any cell of gridview.

Rather than this.. You should use Gridview onRowCommand Event for this purpose.

Get your desired control in this and call the remaining code on the basis of that.
Muhamad Faizan Khan 28-Oct-13 1:19am    
onRowCommand i didnt find in propery window
VICK 28-Oct-13 1:33am    
Re try.. rightclick on Gridview's Error and go to properties.

for detailed info visit.

http://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.gridview.rowcommand.aspx

and

http://www.codeproject.com/Tips/564619/Example-of-gridview-rowcommand-on-Button-Click.

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