anurodhora
June 3rd, 2009, 05:56 AM
Hi All,
My aim is not to fire selection changed event when combo value is changed through code.I have written following code:
XAML
=====
<Window x:Class="TestCombo.Window1" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="Window1" Height="300" Width="300">
<Grid>
<Grid.RowDefinitions>
<RowDefinition>
</RowDefinition>
<RowDefinition>
</RowDefinition>
</Grid.RowDefinitions>
<ComboBox Width="100" IsTextSearchEnabled="False" VerticalAlignment="Center" IsEditable="True" HorizontalAlignment="Center" Name="cmbTest" SelectionChanged="cmbTest_SelectionChanged"/>
<Button Grid.Row="1" Click="Button_Click" Content="Set Combo Value"/>
</Grid>
</Window>
Code Behind
=========
Public Window1()
{
InitializeComponent();
cmbTest.Items.Add("50");
cmbTest.Items.Add("100");
cmbTest.Items.Add("200")
}
private void cmbTest_SelectionChanged(object sender, SelectionChangedEventArgs e)
{
MessageBox.Show("Selection Changed");
}
private void Button_Click(object sender, RoutedEventArgs e)
{
cmbTest.Text = "25";
}
Problem Scenario
==============
1) Run the application select 100 from combo drop down and you will see "Selection Changed" messagebox coming up.
2) Now click the button "Set Combo Value" see combo text now changed to 25.
3) Now again try to set combo value to "100" from drop down and notice interestingly nothing will happen and combo would still remain at value 25.
How can i avoid this strange behavior?
Plese suggest.
Thanks,
Anurodh
My aim is not to fire selection changed event when combo value is changed through code.I have written following code:
XAML
=====
<Window x:Class="TestCombo.Window1" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="Window1" Height="300" Width="300">
<Grid>
<Grid.RowDefinitions>
<RowDefinition>
</RowDefinition>
<RowDefinition>
</RowDefinition>
</Grid.RowDefinitions>
<ComboBox Width="100" IsTextSearchEnabled="False" VerticalAlignment="Center" IsEditable="True" HorizontalAlignment="Center" Name="cmbTest" SelectionChanged="cmbTest_SelectionChanged"/>
<Button Grid.Row="1" Click="Button_Click" Content="Set Combo Value"/>
</Grid>
</Window>
Code Behind
=========
Public Window1()
{
InitializeComponent();
cmbTest.Items.Add("50");
cmbTest.Items.Add("100");
cmbTest.Items.Add("200")
}
private void cmbTest_SelectionChanged(object sender, SelectionChangedEventArgs e)
{
MessageBox.Show("Selection Changed");
}
private void Button_Click(object sender, RoutedEventArgs e)
{
cmbTest.Text = "25";
}
Problem Scenario
==============
1) Run the application select 100 from combo drop down and you will see "Selection Changed" messagebox coming up.
2) Now click the button "Set Combo Value" see combo text now changed to 25.
3) Now again try to set combo value to "100" from drop down and notice interestingly nothing will happen and combo would still remain at value 25.
How can i avoid this strange behavior?
Plese suggest.
Thanks,
Anurodh