0

I wanted to know which is the right event to choose for making changes according to DataGridView checkbox cell value.

I want to do "A" when the checkbox is Checked and "B" when it's unchecked.

I've used CurrentCellDirtyStateChanged event and it worked partially. if i'm changing the value and then staying in the cell and change it again it causes unwanted behaviour(calling the cellclick event).

how can i prevent it?

4
  • From msdn: To commit the change when the cell is clicked, you must handle the DataGridView.CurrentCellDirtyStateChanged event. In the handler, if the current cell is a check box cell, call the DataGridView.CommitEdit method and pass in the Commit value. Are you calling the Commit edit and passing the Commit value? Commented Mar 17, 2017 at 15:42
  • I read it already but i don't know how to use it with my code. Commented Mar 17, 2017 at 15:57
  • I don't know how to use it with your code either because I dont have your code... Edit your question and add your code. Also add tags to indicate you are using windows forms so people don't suggest web solutions etc. Commented Mar 17, 2017 at 16:02
  • This is my code : image.prntscr.com/image/6ddcebfba5dc4af1a7e665d01d3c3ee8.png Commented Mar 17, 2017 at 16:07

1 Answer 1

1

Try this:

<asp:TemplateField HeaderText="View">
   <ItemTemplate>
      <asp:CheckBox ID="chkview" runat="server" AutoPostBack="true" OnCheckedChanged="chkview_CheckedChanged" />
   </ItemTemplate>
</asp:TemplateField>

and in the .cs page,

protected void chkview_CheckedChanged(object sender, EventArgs e)
{
    //Handle desired behavior 

}
Sign up to request clarification or add additional context in comments.

3 Comments

Thank You , but i'm using a Form in C# not asp.
Are you using ASP.net or winforms?
winforms, I forgot to mention , sorry

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.