There is a database of enterprises of 1000 entries. There is a form in which you need to select one of the enterprises from the list and then do something with it (no matter what). How to organize an effective choice from such number of lines? For example, they are all in the combo box and we begin to enter the name in the combo box and we immediately filter out the superfluous. How to make it responsive and beautiful? At least push the path. I will invent the implementation myself.

2 answers 2

Use AutoComplete . For example, put the combo box myCMB.AutoCompleteMode = AutoCompleteMode.SuggestAppend and AutoCompleteSource = AutoCompleteSource.CustomSource . This will automatically sort the drop-down list.

  • Auto completion is good. But if the name of the enterprises will be in the form of Kolosok LLC, it will be necessary to introduce LLC K ... so that it issues at least enterprises with the letter K, this is not very convenient. I understand it’s impossible to fasten my composer?
  • one
    For this you need to get stuck like this - ogorank
  • I will explain a little: in the combobox after the KeyPress event triggers, you need to filter the data and insert it into the list - ogorank
  • Also an option, by the way the least laborious :) If you use LINQ - Chelios
  • You can ask a question, so I filtered by the first pressed letter, let’s say, 200 options. I brought them in DataSourse combo box and automatically got an item. And I do not need it. It works somehow not correctly. - Chelios

In Wpf, I did this: Xaml:

  <Label Content="Searched text:"/> <TextBox Grid.Column="1" Text="{Binding FilterString, UpdateSourceTrigger=PropertyChanged}" /> </Grid> <DataGrid Grid.Row="1" ItemsSource="{Binding Path=MyList, Mode=OneWay, UpdateSourceTrigger=PropertyChanged}"> <DataGrid.Columns> <DataGridTextColumn Header="Name" Binding="{Binding Name, Mode=OneWay}" Width="40*" SortDirection="Ascending"/> <DataGridTextColumn Header="Version" Binding="{Binding Version, Mode=OneWay}" Width="10*" /> </DataGrid.Columns> </DataGrid> 

Code:

  private ICollectionView _myList; public ICollectionView MyList { get { return _myList; } set { _myList = value; NotifyPropertyChanged("MyList"); } } private string _filterString = string.Empty; public bool FilterTask(object value) { var entry = value as MyListModel; return entry != null && (string.IsNullOrEmpty(_filterString) || entry.DisplayName.ToLower().Contains(_filterString.ToLower())); } public string FilterString { get { return _filterString; } set { _filterString = value; NotifyPropertyChanged("FilterString"); if (_myList != null) _myList.Refresh(); } } 

Works with 3000 entries fast. Here the text box acts as a filter and filters the table, but you can change the implementation for yourself.

Oh yes, in the constructor when assigning a collection of values ​​you need to specify:

 MyList.Filter = FilterTask; 
  • one
    I 'll try, thanks for the advice - Chelios