简体   繁体   中英

Changing Checkbox Value in datagridview C# winforms

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?

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 

}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM