Click here to Skip to main content
Rate this: bad
good
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.
 

 
//code
 
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;
 
               }
 
               else
               {
                   cbAssigned.Enabled = false;
                   cbStatus.Enabled = false;
                   cbWorkFlow.Enabled = false;
               }
           }
       }
Posted 20-Mar-13 4:44am
Edited 20-Mar-13 5:21am
v4
Comments
Neetesh Agarwal at 20-Mar-13 10:23am
   
If you dont know answer then why you downvote.........
Prasad Khandekar at 20-Mar-13 10:24am
   
Neetesh please have a look at this doc (http://msdn.microsoft.com/en-us/library/system.windows.forms.datagridview.currentcelldirtystatechanged.aspx). It should help you.
Neetesh Agarwal at 20-Mar-13 10:28am
   
Thanks Prasad ji. I am finding this.
Neetesh Agarwal at 20-Mar-13 10:52am
   
Its working fine,,,,,,

1 solution

Rate this: bad
good
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:
http://msdn.microsoft.com/en-us/library/system.windows.forms.checkbox.checkedchanged.aspx[^].
 
To get a control (to add an event handler to the invocation list of its event instance, as in your case): http://msdn.microsoft.com/en-us/library/system.windows.forms.datagridview.editingcontrol.aspx.
 
[EDIT]
 
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;
                    HandleCellCheckBoxCheckedChanged(
                        eventArgs.RowIndex,
                        eventArgs.ColumnIndex,
                        state);
                } // if checkBoxCell
                //...
            }; // gridView.CellValueChanged
        } // SetupGridViewEditEvents

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

 
[EDIT]
 
Code sample fixed on 3/28/2013. Sorry for the inconvenience.
 
—SA
  Permalink  
v6
Comments
Neetesh Agarwal at 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 at 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.
—SA
Sergey Alexandrovich Kryukov at 20-Mar-13 10:32am
   
Please see updated answer, after [EDIT].
—SA
Neetesh Agarwal at 20-Mar-13 10:28am
   
http://msdn.microsoft.com/en-us/library/system.windows.forms.datagridview.currentcelldirtystatechanged.aspx
Neetesh Agarwal at 20-Mar-13 10:52am
   
May be but my answer is here.
http://msdn.microsoft.com/en-us/library/system.windows.forms.datagridview.currentcelldirtystatechanged.aspx
By the way thanks for ur time .
Sergey Alexandrovich Kryukov at 20-Mar-13 11:13am
   
No, this is a bad, pull approach, you need a push.
—SA
Sergey Alexandrovich Kryukov at 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.
—SA
Neetesh Agarwal at 21-Mar-13 3:11am
   
Thanks Sir,
I will sure go through that......
Sergey Alexandrovich Kryukov at 21-Mar-13 10:31am
   
Great.
Good luck, call again.
—SA
Maciej Los at 28-Mar-13 12:41pm
   
+5
Sergey Alexandrovich Kryukov at 28-Mar-13 13:13pm
   
Thank you, Maciej.
—SA

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

  Print Answers RSS
0 OriginalGriff 319
1 Maciej Los 295
2 Sergey Alexandrovich Kryukov 230
3 CPallini 205
4 Sinisa Hajnal 166
0 OriginalGriff 7,760
1 Sergey Alexandrovich Kryukov 7,072
2 DamithSL 5,604
3 Manas Bhardwaj 4,986
4 Maciej Los 4,785


Advertise | Privacy | Mobile
Web02 | 2.8.1411023.1 | Last Updated 28 Mar 2013
Copyright © CodeProject, 1999-2014
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