Articles in this section
Category / Section

How do I insert a Combobox in a cell using Essential XlsIO?

7 mins read

Syncfusion Essential XlsIO is a .NET Excel library to create, read and edit Excel documents. Using this library, you can add Combo Box into an Excel cell.

Steps to insert a Combo Box into an Excel cell programmatically:

  1. Create a new C# Windows Forms application in Visual Studio.

Create Windows Forms application

Create Windows Forms application

  1. Install the Syncfusion.XlsIO.WinForms NuGet package as reference to your .NET Framework application from NuGet.org.

Add NuGet package to the project

Add NuGet package to the project

  1. Add a new button in Form1.Designer.cs file to create an Excel file with Combo Box.

 

C#

private Button btnCreate;
private Label label;
 
private void InitializeComponent()
{
    this.btnCreate = new System.Windows.Forms.Button();
    this.label = new System.Windows.Forms.Label();
    this.SuspendLayout();
 
    // 
    // addComboBox
    // 
    this.btnCreate.Location = new System.Drawing.Point(119, 99);
    this.btnCreate.Name = "btnCreate";
    this.btnCreate.Size = new System.Drawing.Size(186, 26);
    this.btnCreate.TabIndex = 1;
    this.btnCreate.Text = "Add Combo Box";
    this.btnCreate.Click += new System.EventHandler(this.addComboBox_Click);
 
    // 
    // label
    // 
    this.label.Location = new System.Drawing.Point(0, 40);
    this.label.Name = "label";
    this.label.Size = new System.Drawing.Size(426, 35);
    this.label.TabIndex = 0;
    this.label.Text = "Click the button to view an Excel spreadsheet generated by Essential XlsIO. Pleas" +
    "e note that MS Excel Viewer or MS Excel is required to view the resultant docume" +
    "nt.";
    this.label.TextAlign = System.Drawing.ContentAlignment.MiddleCenter;
 
    // 
    // Form1
    // 
    this.ClientSize = new System.Drawing.Size(450, 150);
    this.Controls.Add(this.label);
    this.Controls.Add(this.btnCreate);
    this.Name = "Form1";
    this.Text = "Create Spreadsheet";
    this.ResumeLayout(false);
}

 

VB.NET

Private label As Label
Private WithEvents btnCreate As Button
 
Private Sub InitializeComponent()
    label = New Label()
    btnCreate = New Button()
 
    'Button
    btnCreate.Location = New Drawing.Point(119, 99)
    btnCreate.Size = New Drawing.Size(186, 26)
    btnCreate.Text = "Add Combo Box"
    AddHandler btnCreate.Click, AddressOf Me.addComboBox_Click
 
    'Label
    label.Location = New Drawing.Point(0, 40)
    label.Size = New Drawing.Size(426, 35)
    label.Text = "Click the button to view an Excel spreadsheet generated by Essential XlsIO. Please note that MS Excel Viewer or MS Excel is required to view the resultant document."
    label.TextAlign = Drawing.ContentAlignment.MiddleCenter
 
    'Create Spreadsheet
    ClientSize = New Drawing.Size(450, 150)
    Controls.Add(btnCreate)
    Controls.Add(label)
    Text = "Create Spreadsheet"
End Sub

 

  1. Include the following namespaces in Form1.cs file.

 

C#

using Syncfusion.XlsIO;

 

VB.NET

Imports Syncfusion.XlsIO

 

  1. Include the following complete code snippet in addComboBox_Click, the button click event, in Form1.cs, to create simple Excel document with Combo Box inserted in an Excel cell.

 

C#

//Initialize ExcelEngine
using (ExcelEngine excelEngine = new ExcelEngine())
{
    //Initialize IApplication
    IApplication application = excelEngine.Excel;
 
    //Set the default application version
    application.DefaultVersion = ExcelVersion.Excel2016;
 
    //Create a new Excel workbook
    IWorkbook workbook = application.Workbooks.Create(1);
 
    //Access the first worksheet in the workbook
    IWorksheet worksheet = workbook.Worksheets[0];
 
    //Add data in worksheet
    worksheet["A2"].Text = "RGB colors";
    worksheet["A3"].Text = "Red";
    worksheet["A4"].Text = "Green";
    worksheet["A5"].Text = "Blue";
    worksheet["B5"].Text = "Selected Index";
 
    //Add a Combo Box in worksheet
    IComboBoxShape comboBox = worksheet.ComboBoxes.AddComboBox(2, 3, 20, 100);
 
    //Assign value to the Combo Box
    comboBox.ListFillRange = worksheet["A3:A5"];
    comboBox.LinkedCell = worksheet["C5"];
    comboBox.SelectedIndex = 2;
 
    //Save the Excel workbook and open it for viewing
    workbook.SaveAs("Output.xlsx");
    System.Diagnostics.Process.Start("Output.xlsx");
}

 

VB.NET

'Initialize ExcelEngine
Using excelEngine As ExcelEngine = New ExcelEngine
    'Initialize IApplication
    Dim application As IApplication = excelEngine.Excel
 
    'Set the default application version
    application.DefaultVersion = ExcelVersion.Excel2016
 
    'Create a new Excel workbook
    Dim workbook As IWorkbook = application.Workbooks.Create(1)
 
    'Access the first worksheet in the workbook
    Dim worksheet As IWorksheet = workbook.Worksheets(0)
 
    'Add data in worksheet
    worksheet("A2").Text = "RGB colors"
    worksheet("A3").Text = "Red"
    worksheet("A4").Text = "Green"
    worksheet("A5").Text = "Blue"
    worksheet("B5").Text = "Selected Index"
 
    'Add a Combo Box in worksheet
    Dim comboBox As IComboBoxShape = worksheet.ComboBoxes.AddComboBox(2, 3, 20, 100)
 
    'Assign value to the Combo Box
    comboBox.ListFillRange = worksheet("A3:A5")
    comboBox.LinkedCell = worksheet("C5")
    comboBox.SelectedIndex = 2
 
    'Save the Excel workbook and open it for viewing
    workbook.SaveAs("Output.xlsx")
    System.Diagnostics.Process.Start("Output.xlsx")
End Using

 

A complete working sample to create an Excel document with Combo Box inserted in an Excel cell can be downloaded from Insert ComboBox in Excel cell.zip.

By executing the program, you will get the Excel file as follows.

Excel file with Combo Box

Excel file with Combo Box

Take a moment to peruse the documentation, where you can find basic worksheet data manipulation options along with features like Conditional Formatting, worksheet calculations through Formulas, adding Charts in worksheet or workbook, organizing and analyzing data through Tables and Pivot Tables, appending multiple records to worksheet using Template Markers, and most importantly PDF and Image conversions with code examples.

Refer here to explore the rich set of Syncfusion Excel (XlsIO) library features.

Note:

Starting with v16.2.0.x, if you reference Syncfusion assemblies from trial setup or from the NuGet feed, include a license key in your projects. Refer the link to learn about generating and registering Syncfusion license key in your application to use the components without trial message.

 

 

Conclusion

I hope you enjoyed learning about how do I insert a Combobox in a cell using Essential XlsIO.

You can refer to our WinForms Excel feature tour page to know about its other groundbreaking feature representations and documentation, and how to quickly get started for configuration specifications. You can also explore our WinForms Excel example to understand how to create and manipulate data.

For current customers, you can check out our components from the License and Downloads page. If you are new to Syncfusion, you can try our 30-day free trial to check out our other controls.

If you have any queries or require clarifications, please let us know in the comments section below. You can also contact us through our support forumsDirect-Trac, or feedback portal. We are always happy to assist you!

Did you find this information helpful?
Yes
No
Help us improve this page
Please provide feedback or comments
Comments (0)
Please sign in to leave a comment
Access denied
Access denied