Click here to Skip to main content
15,922,512 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Dear All,

In my WPF Application, I have few controls viz., List Box(A) and ComboBox(B) and TextBox(C), I need to disable the entities, ie., If User selects (A) any value from List Box, Both items in ComboBox and TextBox should be disabled and vice versa.
viz.,

<listbox name="MyListBox" verticalalignment="Top" .isenabled="...>Value 1/Value2/Value3</ListBox><br mode=" hold=" /><<br mode=" top=" SelectedIndex=" combo1="><<br mode=" mytextbox="" height="20">In Case we had to target the problem using Checkbox(relative to above controls) We would target using below syntax "{Binding ElementName="Checkbox", IsPath="IsChecked}",... etc.,

But, how to effect xaml Syntax if the controls are other than Checkbox.? and in context of mutually exclusive for above three entities.?

Any Help in resolving the above would be appreciable.


With Regards,
Samanth_90
Posted
Updated 25-Mar-12 6:13am
v2
Comments
Member 7985084 26-Mar-12 3:54am    
I am getting Exception when I follow the above code logic, could anyone throw light on the same, I modified the code incorporating the change mentioned, MyFile.xaml ...... <Listbox Name="MyListBox" SelectionChanged="ListBox_SelectionChanged" .../> ...... ...... MyFile.xaml.cs private void ListBox_SelectionChanged(object sender, SelectionChangedEventArgs e) { //...... textbox1.IsEnabled = false; combobox1.IsEnabled = false; } I get assertion on above change, Please let me know we can resolve the same? or any other alternative approach to target the above problem. The Exception of type "System.NullReferenceException" occurred, and was not handled in user code. Additional Information: Object Reference not set to an Instance of an Object. Thanks & Regards, Samanth_90

1 solution

in easy way fist you need to make one selectionChanged event for you list box and here make your combobox and textbox isenabled proeprty as false
C#
private void ListBox_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            //......
            textbox1.IsEnabled = false;
            combobox1.IsEnabled = false;
        }

here
is user Chang value for list box that means that select any of item in list box at a time combobox and textbox will be disabled
 
Share this answer
 
Comments
Member 7985084 26-Mar-12 3:14am    
I am getting Exception when I follow the above code logic, could anyone throw light on the same, I modified the code incorporating the change mentioned, MyFile.xaml ...... <Listbox Name="MyListBox" SelectionChanged="ListBox_SelectionChanged" .../> ...... ...... MyFile.xaml.cs private void ListBox_SelectionChanged(object sender, SelectionChangedEventArgs e) { //...... textbox1.IsEnabled = false; combobox1.IsEnabled = false; } I get assertion on above change, Please let me know we can resolve the same? or any other alternative approach to target the above problem.

The Exception of type "System.NullReferenceException" occurred, and was not handled in user code.
Additional Information: Object Reference not set to an Instance of an Object.


Thanks & Regards, Samanth_90

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