ComboListCell creates an editable combo box cell: users can type freely, rely on auto-completion, or pick from a drop-down list. Compared to DropdownListCell, it keeps the suggestions but also accepts new values. The examples below assume that standard namespaces (e.g., System.Collections.Generic, System.Linq) are in scope when lists are used.

Create a combo list cell

using unvell.ReoGrid;
using unvell.ReoGrid.CellTypes;

var sheet = grid.CurrentWorksheet;
var combo = new ComboListCell(new[] { "Apple", "Banana", "Orange", "Applause", "Appreciate" });
sheet.Cells["C3"].Body = combo;

Populate options later by keeping a mutable list and passing it in:

var items = new List<string> { "Alpha", "Beta", "Gamma" };
var combo = new ComboListCell(items);
items.Add("Delta"); // the list stays linked to the cell
sheet["B5"] = combo;

You can also bind to a range so the list reflects cell contents:

var range = new ReferenceRange(sheet, new RangePosition("A2:A20"));
sheet["D2"] = new ComboListCell(range);

Auto completion

Auto completion is enabled by default. Disable it if you only want manual typing or the drop-down:

combo.EnableAutoCompletion = false;

Provide custom matching logic (the default is a case-insensitive prefix match). Returning true keeps the item in the suggestion list and lets ReoGrid append the remaining characters when the user types:

combo.AutoCompleteComparerator = (item, text) =>
{
    if (string.IsNullOrWhiteSpace(text)) return false;
    return item.Contains(text, StringComparison.OrdinalIgnoreCase); // substring match
};

For large or remote data sets, supply your own search provider. It is invoked during typing; return the items that should appear in the drop-down for the current text:

combo.CandidationListSearchProvider = text =>
{
    return ProductSearch(text?.ToString())
        .Take(20)
        .ToList();
};

Handle selection and edits

React when the user picks an item or commits a typed value:

combo.SelectedItemChanged += (s, e) =>
{
    Console.WriteLine($"Selected: {combo.SelectedItem}");
};

Capture new values the user has typed and keep them for later suggestions (when the cell is backed by your own list):

var items = new List<string> { "Alpha", "Beta" };
var combo = new ComboListCell(items);
sheet["B5"] = combo;

sheet.AfterCellEdit += (s, e) =>
{
    if (ReferenceEquals(e.Cell.Body, combo) &&
        e.NewData is string text &&
        !string.IsNullOrWhiteSpace(text) &&
        !items.Contains(text))
    {
        items.Add(text);
    }
};

Keyboard behavior matches common combo boxes: Up/Down moves through the list, Enter/Space confirms the highlighted item, Tab confirms and moves to the next cell, and Esc closes the drop-down.

Styling (WPF)

On WPF, adjust the list appearance through Style:

#if WPF
combo.Style.TextColor = SolidColor.DarkBlue;
combo.Style.BackColor = SolidColor.LightYellow;
combo.Style.FontSize = 14;
combo.Style.FontWeight = FontWeights.Bold;
#endif

Override the ListBox template (WPF)

You can swap in a custom ControlTemplate/ItemTemplate for the drop-down ListBox. Define the templates in XAML and assign them when the drop-down opens:

<Window.Resources>
  <ControlTemplate x:Key="ReoGridComboListTemplate" TargetType="ListBox">
    <Border Background="#101820" CornerRadius="6" Padding="4">
      <ScrollViewer Focusable="False">
        <ItemsPresenter />
      </ScrollViewer>
    </Border>
  </ControlTemplate>

  <DataTemplate x:Key="ReoGridComboItemTemplate">
    <StackPanel Orientation="Horizontal" Margin="4,2">
      <Ellipse Width="6" Height="6" Fill="#FF7A00" Margin="0,0,6,0"/>
      <TextBlock Text="{Binding}" Foreground="White"/>
    </StackPanel>
  </DataTemplate>
</Window.Resources>

Wire it up in code:

#if WPF
combo.DropdownOpened += (s, e) =>
{
    if (((ComboListCell)s).DropdownControl is ListBox listBox)
    {
        listBox.Template = (ControlTemplate)FindResource("ReoGridComboListTemplate");
        listBox.ItemTemplate = (DataTemplate)FindResource("ReoGridComboItemTemplate");
    }
};
#endif

Extend the control

Subclass ComboListCell when you need deeper customization (e.g., overriding keyboard handling or providing specialized data binding):

class MyComboListCell : ComboListCell
{
    // override members or add helpers here
}
Was this article helpful?