Quantcast
Channel: Windows Presentation Foundation (WPF) forum
Viewing all articles
Browse latest Browse all 18858

Reverting back to other Value in ComboBox

$
0
0

Hello,

I have a ComboBox which is binded with a Property CoverageCode (P,T,"",etc...) and also i have a CoverageText Property which is binded with the description (Primary,Tertiary,Not Available, etc..). They both are from same List which is binded to ComboBox.

<ComboBox IsEditable="True" ItemsSource="{Binding CoverageTypeList}"  SelectedValue="{Binding CoverageCode,UpdateSourceTrigger=PropertyChanged,Mode=TwoWay}"
Text="{Binding CoverageText, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}"
DisplayMemberPath="Description" SelectedValuePath="ItemKey"
 />

Below are the Properties I am using :

public string CoverageCode { get { return _CoverageCode; } set { _CoverageCode = value;

Coverage = GetCoverageText(_CoverageCode); CoverageText = Coverage; RaisePropertyChanged(() => CoverageCode); } } public string CoverageText { get { return _CoverageText; } set { if (!CoverageTypeList.Any(x => x.Description.StartsWith(value))) { MessageBox.Show("Hi"); CoverageCode = string.Empty; return; } _CoverageText = value; RaisePropertyChanged(() => PolicyCoverageText); } }

So I want to Show some messagebox and then revert back to some other value (Not Available in this case, with CoverageCode = String.Empty). 

What happens that as soon as I type some invalid character, say "F" in the Combobox (Which does not starts from the strings present in the list), the "Hi" MessageBox does appears but "F" does not get removed from the Combobox and "Not Available" does not get selected.

Please suggest.

Thanks,

Abdi


Viewing all articles
Browse latest Browse all 18858

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>