kAsdh
kAsdh

Reputation: 366

Set check box value as checked depends on text box value in WPF

In WPF window, there are 2 textbox and buttons, when we enter values in to text box , it displays values in a datagrid view! Based on textbox_2 values datagrid view checkbox column need to be add the values.

enter image description here

For example, when add the Yes in to text box checkbox should be checked!

how can I accomplish this!

Upvotes: 0

Views: 954

Answers (2)

Siby Sunny
Siby Sunny

Reputation: 752

In Model class define the Active/Deactive as bool type. then on add button click check the text entered and if it is yes then set the Active/Deactive as true then bind it into datagrid. then you will get the required ouput as you wish

Upvotes: 1

benPearce
benPearce

Reputation: 38333

This is very easily accomplished with the MVVM pattern.

Create an object which implements the INotifyPropertyChanged interface(https://msdn.microsoft.com/en-us/library/system.componentmodel.inotifypropertychanged(v=vs.110).aspx). This is your ViewModel.

Then set the datacontext of the Window/UserControl to and instance of this class. In the class create two properties, one a boolean and one a string. In the setter of the string set the boolean property to true if the string is being set to "Yes".

Then in the Xaml bind the IsChecked property of the checkbox to the boolean property on your ViewModel, and bind the Text property of the TextBox to the string property.

MVVM Example: WPF MVVM INotifyPropertyChanged Implementation - Model or ViewModel

Upvotes: 0

Related Questions