1

I have a ComboBox with 2 items. But on the loaded page I print an item not from the datasource which also has index 0.

How can I detect the click event on the first item (index 0) from the dropdownlist.

I need to distinguish the object A index 0 which is the displayed Item and the object B index 0 from the dropdownlist. The Object A is displayed using text property of the combobox, so its assigned inndex is 0.

I can't use SelectionChanged because the event is based on SelectedIndex. here both have the same.

Here is some code, but not so helpfull (I tried using PreviewMouseLeftButtonUp, but the event is not triggered on item) :

XAML

<telerik:RadComboBox x:Name="Combo" ItemsSource="{Binding ListeIndexationInit, Mode=OneWay}" SelectedValue="{Binding SelectedCodeIndexInitVentePV, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" PreviewMouseLeftButtonUp="Combo_PreviewMouseLeftButtonUp">

My code Behind xaml.cs

//Does not get the right index
private void RadComboBox_LostFocus(object sender, RoutedEventArgs e)
{
    RefOffreIndex value = Combo.SelectedValue as RefOffreIndex;
    if (value != null)
    {
        Combo.Text = value.ToString();
    }
    Combo.SelectedIndex = -1;
    var SelectionBoxItem = Combo.SelectionBoxItem;
    Combo.SelectedItem = value;
    var bindingExpression = Combo.GetBindingExpression(RadComboBox.SelectedItemProperty);
}
//Never triggered
private void Combo_SourceUpdated(object sender, DataTransferEventArgs e)
{
    Combo.SelectedIndex = -1;
}
//Event is too early
private void Combo_PreviewMouseLeftButtonUp(object sender, MouseButtonEventArgs e)
{
    var toto = 2;
}    
Benoît
  • 143
  • 1
  • 2
  • 15
  • is this asp.net or xaml? they are quite different from each other – Simon Price Sep 07 '17 at 13:44
  • also, show us some code – Simon Price Sep 07 '17 at 13:45
  • It is in xaml, I edited some code. Not sure it can help. – Benoît Sep 07 '17 at 13:49
  • take a look at how an observable collection works in WPF. Ive used it in the past but not for a good few years at an old company. Take a look at this question https://stackoverflow.com/questions/16197928/wpf-combobox-binding-to-observablecollection and google https://www.google.fr/search?q=observablecollection+combobox+wpf&oq=observablecollection+com&gs_l=psy-ab.3.1.0l2j0i22i30k1l2.150595.150898.0.152793.4.4.0.0.0.0.103.254.3j1.4.0....0...1.1.64.psy-ab..0.4.253.Q6xzBImaae4 This link should give you a set of results that will help – Simon Price Sep 07 '17 at 14:03
  • Thanks I'll check this, what I wan't to do is to invoke a method when the value changed, not the index. – Benoît Sep 07 '17 at 14:16
  • This should probably do for you then – Simon Price Sep 07 '17 at 14:55

0 Answers0