I have two comboboxes. First combobox is for selecting the manager and the second is for selecting Asst. MAnager. But, the source names are same in the both comboxes. Therefore, for example, if I select ” James” from first combobox then I won’t to select it from the second combobox. When I click on “James” in the second combobox, it should give me an error and must not select “JAmes”.
I wrote that code into the second combobox’s selection_changed event:
if (Manager.SelectedItem == Asst_MAnager.SelectedItem)
{
MessageBox.Show("You must change Asst_Manager");
}
That is right , if I select same item then it gives me the error message. But, still it selects the same item after error message. My WPF code is below. Could you give me any idea?
<local:ComboBoxCW Grid.Row="1" Grid.Column="1" Grid.ColumnSpan="3" x:Name="Manager" Text="" Background="#FFC8D2E8" Margin="0,0,0,3"
SelectedID="{Binding Path=[Manager}" />
<local:ComboBoxCW Grid.Row="2" Grid.Column="1" Grid.ColumnSpan="3" x:Name="Asst_Manager" Text="" Background="#FFC8D2E8" CWListName="Assistant Manager" Margin="0,0,0,3"
SelectedID="{Binding Path=[Asst_Manager]}" SelectionChanged="Asst_Manager_SelectionChanged" />
Since your comboboxes are databound, you can’t set the SelectedIndex to -1 (which should deselect any choices you’ve made, normally), and would look like this:
So, I would suggest in your first item in each box to be “Select a Name”. That way you can do:
Or something similar. It’s not pretty, and by far not the best way. But it’s simple, and gets the job done.