0

How do i data bind a checkbox?

i have a checkbox and a couple of textboxes and a datagrid view. When i click next it goes through the data in the datagrid and updates other values such as a textbox to correspond to the data in the datagrid. This isent working for a check box though.

roomNoTextBox.DataBindings.Add(new Binding("Text", bsRooms, "RoomNo"));

gymCheckBox.DataBindings.Add(new Binding("Text", bsRooms, "Gym"));

2 Answers 2

4

Try using the checked property instead:

gymCheckBox.DataBindings.Add(new Binding("Checked", bsRooms, "Gym"));
Sign up to request clarification or add additional context in comments.

Comments

0

Try using the checked property instead:

gymCheckBox.DataBindings.Add(new Binding("Checked", bsRooms, "Gym"));

This is correct. But the one thing you need to know (which took me half an hour just now), the checkbox needs to validate (with the default setting). So it needs to lose focus for example.

So I found the better solution would be:

gymCheckBox.DataBindings.Add(new Binding("Checked", bsRooms, "Gym", false, DataSourceUpdateMode.OnPropertyChanged));

Comments

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.