Click here to Skip to main content
15,901,205 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
hi,
i have a form1, form2
in which form1 contains a datagridview, new, delete buttons... when we click on new button form2 should open where data should be inserted... after giving all the values and click on save button on form2 and after form2 is closed the inserted(saved)data will be filled in datagridview in form1...

all the things are going in a right way... but i stucked on
when we double click the values in the datagridview of form1, form2 should be opened where previously what data is entered in the fields should be like that only...


can you please help in this puzzle...
Posted
Comments
MuhammadUSman1 13-Sep-14 0:54am    
Fire cell click event and track cell index , if button cell clicked by user then Open RequiredForm or take required action else ignore it.
chaitanya556 13-Sep-14 0:58am    
sorry, i didn't get you...
MuhammadUSman1 13-Sep-14 1:02am    
Which events you are using for this purpose?
chaitanya556 13-Sep-14 1:02am    
im using cell double click event
MuhammadUSman1 13-Sep-14 1:10am    
Check Solution

1 solution

C#
//try following code
//Create following variable on class level not here
// it is just for your testing purpose.
                var AddNewCellIndex = 3;
                var UpdateCellIndex = 4; 
                var deleteCellIndex = 5;
   void dataGridView1_CellDoubleClick(object sender, DataGridViewCellEventArgs e)
        {
            try
            {

                if (e.ColumnIndex== AddNewCellIndex)
                {
                    //you open new form here 
                }
                else if (e.ColumnIndex==UpdateCellIndex)
                {
                    //you open update form or what you are using
                }
                else if (e.ColumnIndex==deleteCellIndex)
                {
                    if (MessageBox.Show("Are you sure you want to delete current row", "Delete", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
                    {
                        //delete code
                    }
                }
                //all other cell click will be ignored.
            }
            catch (Exception)
            {
                
                throw;
            }
        }


if any issue then let me know.

->M.U
 
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