Alright, so I have a datagridview that I'm populating with a datatable, and I have added a button column. Now I am trying to use this button's click event to open a new child form. I can't for the life of me figure out what I've done wrong. When I click the button absolutely nothing happens. No error, nothing in debug, help me please.

Here is what I have so far...

public partial class Project : Form
        DataGridViewButtonColumn view;
       public Project()

            view = new DataGridViewButtonColumn();
            view.HeaderText = "View";
            view.Text = "View";
            view.UseColumnTextForButtonValue = true;
            view.Width = 50;
        public void dGvExisting_CellContentClick(object sender, DataGridViewCellEventArgs e)
                int curRow = int.Parse(e.RowIndex.ToString());

                if (dGvExisting.Columns[e.ColumnIndex] == view && curRow >= 0)
                    ViewProject newView = new ViewProject();
                    newView.MdiParent = Form1.ActiveForm;

I simply need to gain access to the click event so that I can add some code to it.

No more problem. Same code now is working, I am befuddled to how that could be but whatever...

private void bindChequeGrid()
            nv.Add("@flag", "ChequeRemainToSubmit");
            dt = hlp.getdatatable("SP_Home", nv);
            if (dt.Rows.Count != 0)
                gv.DataSource = dt;               
                //add Button
                DataGridViewButtonColumn btnDelete = new DataGridViewButtonColumn();
                btnDelete.Name = "btnSubmit";
                btnDelete.Text = "Submit";
                btnDelete.HeaderText = "Submit";
                btnDelete.UseColumnTextForButtonValue = true;
        private void gv_CellContentClick(object sender, DataGridViewCellEventArgs e)
            if (e.ColumnIndex == 9) //Button Submit is located in 9th column            
                //here is my code

// i hv add button in DataGridview. On clicking button first time it return correct columnIndex(i.e 9) but when i click on it again it return me 0 columnIndex.........why it is happening....

Be a part of the DaniWeb community

We're a friendly, industry-focused community of 1.20 million developers, IT pros, digital marketers, and technology enthusiasts learning and sharing knowledge.