怀疑c#中datagridview中的单元格双击事件 [英] doubt on cell double click event in datagridview in c#

查看:325
本文介绍了怀疑c#中datagridview中的单元格双击事件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



i有一个form1,form2

,其中form1包含一个datagridview,new,delete按钮......当我们点击新按钮form2应该打开的地方应该插入数据...在给出所有值并单击form2上的保存按钮后,在form2关闭后,插入(保存)的数据将填入form1的datagridview ...



所有的事情都以正确的方式进行......但是当我们双击form1的datagridview中的值时,我坚持

,form2应该打开以前哪些数据在字段中输入应该只是那样...





你能帮忙解决这个难题......


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

推荐答案

//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;
            }
        }





如有任何问题请告诉我。



- > MU



if any issue then let me know.

->M.U


这篇关于怀疑c#中datagridview中的单元格双击事件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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