Click here to Skip to main content
15,889,472 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
i have Submit column button in datagridview but code is not executing.

i want to edit or update for some columns but i don't how to write the code for that.

i tried as below but code is not executing.

What I have tried:

C#
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace updatebuttoninDG
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void dataGridView1_CellContentClick(object sender, DataGridViewCellEventArgs e)
        {
            if(dataGridView1.Columns[e.ColumnIndex].Name == "Submit")
            {
                MessageBox.Show("Comments Submitted", "Message", MessageBoxButtons.OK, MessageBoxIcon.Information);
                customersBindingSource.Insert(4,Submit);
            }
        }

        private void Form1_Load(object sender, EventArgs e)
        {
            // TODO: This line of code loads data into the 'savedata.Customers' table. You can move, or remove it, as needed.
            this.customersTableAdapter.Fill(this.savedata.Customers);

        }
    }
}
Posted
Updated 27-Apr-18 11:35am
v3

1 solution

The first question is: Is the event handler bound to the CellContentClick event? Using the designer, select the datagridview and switch to event. Ensure that CellContentClick is properly wired to this handler.

If the above is fine, place a breakpoint on the first line of the event handler. Investigate the condition. Is the column name Submit or something else
 
Share this answer
 
Comments
Prateek gsharma 28-Apr-18 10:39am    
yes CellContentClick is properly wired.

Submit is the button column name.
Wendelius 28-Apr-18 12:37pm    
So if event wiring is ok, what happened when you put the breakpoint into the method? did you investigate that

dataGridView1.Columns[e.ColumnIndex].Name

is really "Submit"

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