Spread WPF 18
Features / Cell Types / Combo Box Cell
In This Topic
    Combo Box Cell
    In This Topic

    Combo box cell displays an editable drop-down list within a cell. Users can expand the drop-down list by clicking the drop-down button, by pressing the F4, or Alt + Down arrow.

    You can configure a combo box cell using the methods and properties of the ComboBoxCellType class in the GrapeCity.Wpf.SpreadSheet.CellType namespace. There are two primary methods of configuring items in a combo box cell:

    Additionally, the drop-down list of a combo box cell can also display items in multiple columns. To enable the multi-column feature of a combo box cell and display items in multiple columns within the drop-down list, set the UseMultipleColumn property to true.

    The following example code binds a combo box cell to a CellTypeCollection and enables the multi-column feature.

    Copy Code
    private void Window_Loaded(object sender, RoutedEventArgs e)
    {
         // Multi - column combo box.
         ComboBoxCellType c = new ComboBoxCellType();
         c.ItemsSource = new CellTypeCollection();
         c.ContentPath = "Name";
         c.UseMultipleColumn = true;
         c.DropDownWidth = 400;
         spreadSheet1.Workbook.ActiveSheet.Columns[0].CellType = c;
         spreadSheet1.Workbook.ActiveSheet.Columns[0].ColumnWidth = 400;
    }
    
    public class CellTypeCollection : List<SpreadCellType>
    {
         public CellTypeCollection()
         {
                Add(new SpreadCellType()
                {
                    Display = new BitmapImage(new Uri(@"Images\TextCellType.png", UriKind.Relative)),
                    Name = "Text",
                    Description = "Only permitted character types can be entered."
                });
                Add(new SpreadCellType()
                {
                    Display = new BitmapImage(new Uri(@"Images\DateCellType.png", UriKind.Relative)),
                    Name = "DateTime",
                    Description = "You can enter a date and time."
                });
                Add(new SpreadCellType()
                {
                    Display = new BitmapImage(new Uri(@"Images\NumberCellType.png", UriKind.Relative)),
                    Name = "Number",
                    Description = "You can enter a number."
                });
                Add(new SpreadCellType()
                {
                    Display = new BitmapImage(new Uri(@"Images\ComboCellType.png", UriKind.Relative)),
                    Name = "ComboBox",
                    Description = "Select data from the combo box."
                });
                Add(new SpreadCellType()
                {
                    Display = new BitmapImage(new Uri(@"Images\ButtonCellType.png", UriKind.Relative)),
                    Name = "Button",
                    Description = "Show the button."
                });
         }
    }
    
    Copy Code
    Private Sub Window_Loaded(sender As Object, e As RoutedEventArgs)
        ' Multi - column combo box.
        Dim c As ComboBoxCellType = New ComboBoxCellType()
        c.ItemsSource = New CellTypeCollection()
        c.ContentPath = "Name"
        c.UseMultipleColumn = True
        c.DropDownWidth = 400
        spreadSheet1.Workbook.ActiveSheet.Columns(0).CellType = c
        spreadSheet1.Workbook.ActiveSheet.Columns(0).ColumnWidth = 400
    End Sub
    
    Public Class CellTypeCollection
        Inherits List(Of SpreadCellType)
        Public Sub New()
            Add(New SpreadCellType() With {
            .Display = New BitmapImage(New Uri("Images\TextCellType.png", UriKind.Relative)),
            .Name = "Text",
            .Description = "Only permitted character types can be entered."
            })
            Add(New SpreadCellType() With {
            .Display = New BitmapImage(New Uri("Images\DateCellType.png", UriKind.Relative)),
            .Name = "DateTime",
            .Description = "You can enter a date and time."
            })
            Add(New SpreadCellType() With {
            .Display = New BitmapImage(New Uri("Images\NumberCellType.png", UriKind.Relative)),
            .Name = "Number",
            .Description = "You can enter a number."
            })
            Add(New SpreadCellType() With {
            .Display = New BitmapImage(New Uri("Images\ComboCellType.png", UriKind.Relative)),
            .Name = "ComboBox",
            .Description = "Select data from the combo box."
            })
            Add(New SpreadCellType() With {
            .Display = New BitmapImage(New Uri("Images\ButtonCellType.png", UriKind.Relative)),
            .Name = "Button",
            .Description = "Show the button."
            })
        End Sub
    End Class