Click here to Skip to main content
11,931,584 members (63,336 online)
Rate this:
Please Sign up or sign in to vote.
See more: C# .NET
Hello friends,

I am working on windows application. IN which I am using datagridview . There is also a checkboxcolumn in datagridview. My need is when I checked the checkboxcell there should be some control enabled and when I unchecked control should be disabled. I am using CellContentClick Event. Should I use something else.


private void dgHelpDesk_CellContentClick(object sender, DataGridViewCellEventArgs e)
           for (int i = 0; i < dgHelpDesk.RowCount; i++)
               if (Convert.ToBoolean(this.dgHelpDesk.Rows[i].Cells["checkboxcolumn"].Value))
                   cbAssigned.Enabled = true;
                   cbStatus.Enabled = true;
                   cbWorkFlow.Enabled = true;
                   cbAssigned.Enabled = false;
                   cbStatus.Enabled = false;
                   cbWorkFlow.Enabled = false;
Posted 20-Mar-13 4:44am
Edited 20-Mar-13 5:21am
Neetesh Agarwal 20-Mar-13 10:23am
If you dont know answer then why you downvote.........
Prasad Khandekar 20-Mar-13 10:24am
Neetesh please have a look at this doc ( It should help you.
Neetesh Agarwal 20-Mar-13 10:28am
Thanks Prasad ji. I am finding this.
Neetesh Agarwal 20-Mar-13 10:52am
Its working fine,,,,,,

1 solution

Rate this: bad
Please Sign up or sign in to vote.

Solution 1

No, you rather need to get an instance of a CheckBox and handle the event CheckBox.CheckedChanged:[^].

To get a control (to add an event handler to the invocation list of its event instance, as in your case):


Okay, as some delicate moment is involved, I'll show you what to do:
void SetupGridViewEditEvents(DataGridView gridView) {
    gridView.CellValueChanged += (sender, eventArgs) => {
        DataGridViewCell cell = gridView.Rows[eventArgs.RowIndex].Cells[eventArgs.ColumnIndex];
        DataGridViewCheckBoxCell checkBoxCell = cell as DataGridViewCheckBoxCell;
        if (checkBoxCell != null) {
            CheckState state = (CheckState)checkBoxCell.Value;
        } // if checkBoxCell
    }; // gridView.CellValueChanged
} // SetupGridViewEditEvents

void HandleCellCheckBoxCheckedChanged(int cellRow, int cellColumn, CheckState state) {
    // you handler logic goes here
} // HandleCellCheckBoxCheckedChanged


Code sample fixed on 3/28/2013. Sorry for the inconvenience.

Neetesh Agarwal 20-Mar-13 10:27am
Hello Sir,

Thanks for reply But thats not the answer of my question. I am asking about checkbox in Gridview.
Sergey Alexandrovich Kryukov 20-Mar-13 10:28am
You did not get it. I am answering about a check box in DataGridView. It contains a set of check boxes.
Sergey Alexandrovich Kryukov 20-Mar-13 10:32am
Please see updated answer, after [EDIT].
Neetesh Agarwal 20-Mar-13 10:28am
Neetesh Agarwal 20-Mar-13 10:52am
May be but my answer is here.
By the way thanks for ur time .
Sergey Alexandrovich Kryukov 20-Mar-13 11:13am
No, this is a bad, pull approach, you need a push.
Sergey Alexandrovich Kryukov 20-Mar-13 11:25am
You should not work around and shift focus. You really need to handle CheckBox event, and nothing else.
Please see my updated answer, after [EDIT].

Seriously, don't do wrong thing again.
Neetesh Agarwal 21-Mar-13 3:11am
Thanks Sir,
I will sure go through that......
Sergey Alexandrovich Kryukov 21-Mar-13 10:31am
Good luck, call again.
Maciej Los 28-Mar-13 12:41pm
Sergey Alexandrovich Kryukov 28-Mar-13 13:13pm
Thank you, Maciej.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month

Advertise | Privacy | Mobile
Web01 | 2.8.151126.1 | Last Updated 28 Mar 2013
Copyright © CodeProject, 1999-2015
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100