Click here to Skip to main content
16,017,488 members
Please Sign up or sign in to vote.
1.22/5 (2 votes)
See more:
My question is about.I have a datagridview in which i have fourth column as

checkbox. When clicking checkbox i want to get checkbox value in code behind. Can anybody help?

What I have tried:

I dont have any code available for now. Im thinking about what should i do with these problems.
Posted
Updated 30-Jan-19 21:50pm
Comments
Member 14127874 30-Jan-19 22:10pm    
Need some idea
The Cool Cat 31-Jan-19 1:48am    
What do you mean by Getting the Checkbox value? Check if it is Check or Unchecked?
Member 14127874 31-Jan-19 1:51am    
I have a YES or NO checkboxes on the datagridview. So, the user will answer yes or no on the datagridview.

The value of yes is 1 and no is 0.
The Cool Cat 31-Jan-19 1:54am    
Once you Update the datagridview and save it, Unchecked checkboxes will automatically have a Value of 0 and Checked will be 1.
Member 14127874 31-Jan-19 3:22am    
Do you have any code there ? Thanks a lot.

1 solution

Hey There. If you are using table adapter or datasets in updating your datagrid view you should just add an update query in your datatable like:

Update YourTableName set YourYesNoColumn=@YourYesNoColumn


The YourYesNoColumn should be an integer which accepts a Value of 0 and 1. Once the Checkbox state in the Datagridview is Checked then it automatically save as 1 and if it is unchecked it will be 0. You don't need to put anything in your code.
 
Share this answer
 
v2
Comments
Member 14127874 31-Jan-19 19:34pm    
I dont get it. Sorry beginner only.
The Cool Cat 31-Jan-19 19:40pm    
Go to your Dataset which is the .xsd file in your project. Find for the Data table which you are using in your Datagridview and add your update Query there.
The Cool Cat 31-Jan-19 19:36pm    
Are you using Datasets for your datagridview?

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