This is a migrated thread and some comments may be shown as answers.
missing entries in drop down but autocomplete finds them
4 Answers 28 Views
This is a migrated thread and some comments may be shown as answers.
Trevor
Top achievements
Rank 1
Trevor asked on 25 Mar 2011, 01:05 PM
Hi,

I have several comboboxes whose itemssource is bound to a common list of strings, when the list changes I raise a propertychanged event. In some circumstances some of the comboboxes display all of the strings and some do not. However the ones not showing all the strings do still find them for autocomplete purposes..

4 Answers, 1 is accepted

Sort by
0
Trevor
Top achievements
Rank 1
answered on 25 Mar 2011, 01:06 PM
Watching the person who is repoducing this, it only happens when they click on the down selector to see if an entry exists and then start typing straight away without any more mouse clicks (as the focus is already in the edit portion of the combo). Now that I know how to cause this I will try in debug with binding tracing on.
0
Trevor
Top achievements
Rank 1
answered on 25 Mar 2011, 05:26 PM
I have created a simple example that demonstrates our problem:

Entering a new text value into one of the combos without extending the dropdown then pressing comit works fine, you can do this repeatedly and then when you open the combo you see your new entries listed. Once you have done this however no futher entries are added to the list.

It is as though the list is 'locked' by being displayed - could this be due to an optimization of some kind? Is there any way to force a re-evaluation of what should be rendered? The binding is still working as auto-complete picks up the new entries even though they are not displayed..

thanks

xaml
<Window x:Class="TestCombos.Window1"
    xmlns:Controls="clr-namespace:Telerik.Windows.Controls;assembly=Telerik.Windows.Controls.Input"
    Title="Window1"
    SizeToContent="WidthAndHeight">
    <Grid>
        <Grid.ColumnDefinitions><ColumnDefinition Width="Auto"/><ColumnDefinition Width="*"/><ColumnDefinition Width="Auto"/></Grid.ColumnDefinitions>
        <Grid.RowDefinitions><RowDefinition Height="Auto"/><RowDefinition Height="Auto"/></Grid.RowDefinitions>
         
        <Label Grid.Column="0" Grid.Row="0" >ComboList</Label>
        <Controls:RadComboBox x:Name="comboEntries" IsEditable="True" Margin="5" Grid.Column="1" Grid.Row="0" Width="150" ItemsSource="{Binding Entries}" SelectedItem="{Binding CurrentEntry}"></Controls:RadComboBox>
        <Button Margin="5" Grid.Column="2" Grid.Row="0" Click="Button_Click">Commit</Button>
 
        <Label Grid.Column="0" Grid.Row="1" >ComboList2</Label>
        <Controls:RadComboBox x:Name="comboEntries2" IsEditable="True" Margin="5" Grid.Column="1" Grid.Row="1" Width="150" ItemsSource="{Binding Entries}" SelectedItem="{Binding CurrentEntry2}"></Controls:RadComboBox>
        <Button Margin="5" Grid.Column="2" Grid.Row="1" Click="Button_Click2">Commit2</Button>
    </Grid>
</Window>

code behind
public partial class Window1 : Window, INotifyPropertyChanged
   {
       public List<string> Entries { get; set; }
       public string CurrentEntry { get; set; }
       public string CurrentEntry2 { get; set; }
 
       public Window1()
       {
           Entries = new List<string> {"entry1", "entry2", "entry3"};
           CurrentEntry = "entry1";
           CurrentEntry2 = "entry2";
           InitializeComponent();
           DataContext = this;
       }
 
       private void Button_Click(object sender, RoutedEventArgs e)
       {
           if (String.IsNullOrEmpty(comboEntries.Text) || Entries.Contains(comboEntries.Text))
               return;
 
           Entries.Add(comboEntries.Text);
           NotifyPropertyChanged("Entries");
       }
 
       private void Button_Click2(object sender, RoutedEventArgs e)
       {
           if (String.IsNullOrEmpty(comboEntries2.Text) || Entries.Contains(comboEntries2.Text))
               return;
 
           Entries.Add(comboEntries2.Text);
           NotifyPropertyChanged("Entries");
       }
 
       public event PropertyChangedEventHandler PropertyChanged;
       private void NotifyPropertyChanged(string propertyName)
       {
           if (PropertyChanged != null)
           {
               PropertyChanged(this, new PropertyChangedEventArgs(propertyName));
           }
       }
0
Accepted
Valeri Hristov
Telerik team
answered on 25 Mar 2011, 05:36 PM
Hi Trevor,

Since you are using List<T> as ItemsSource, RadComboBox does not receive notifications when you add or remove items from the list. The first time you open the dropdown the control creates RadComboBoxItem containers for each item in the items source and unless it receives a change notification it does not add/remove containers anymore. To resolve the problem you need to use ObservableCollection<T> as ItemsSource.

The notification for the Entries property does not work since you do not change the value of the Entries property (the collection itself hasn't changed, only its children).

Regards,
Valeri Hristov
the Telerik team
0
Trevor
Top achievements
Rank 1
answered on 25 Mar 2011, 06:16 PM
Many thanks for the swift response!

Now that you have pointed that out it makes sense and I should have thought of it. I think I had discounted updating of the binding as the autocomplete was finding the new entries.
Asked by
Trevor
Top achievements
Rank 1
Answers by
Trevor
Top achievements
Rank 1
Valeri Hristov
Telerik team
Share this question
or