I’m trying to create a windows form application using c# and spire.XLS where there are 2 combo boxes in a form. How do I make those combo boxes cascading like below:
Situation 1:
When the form loads the first combo box should show a drop down of the column names mentioned in the workbook(say “Sheet1” if there are more than 1 sheet).
When I select a value from the first combo box then the second combo box should show a drop down with the same column names minus the item selected in combo box 1.
Situation 2:
When the form loads the first combo box should show a drop down of the column names mentioned in the workbook(say “Sheet1” if there are more than 1 sheet).
When I select a value from the first combo box e.g. ERICOM, then the second combo box should show a drop down of the respective Bill Date in the format that is in the sheet i.e.
17 October 2020
05 December 2020
08 December 2020
07 January 2021
05 January 2021
07 January 2021
03 February 2021
05 February 2021
How can I do this?
I've done the below for Situation 1 but it's not working:
- Code: Select all
public CellRange[] crs=null;
public Worksheet sheet=null;
public Workbook workbook=null;
void MainFormLoad(object sender, EventArgs e)
{
try {
Workbook workbook = new Workbook();
workbook.LoadFromFile(@"E:\ABC\bill_consumables.xlsx");
Worksheet sheet = workbook.Worksheets[0];
CellRange[] crs = sheet.Rows[0].Cells;
foreach (CellRange cr in crs)
{
if (!String.IsNullOrEmpty(cr.Value2.ToString()))
{
comboBox1.Items.Add(cr.Value);
}
}
workbook.Dispose();
} catch (Exception ex) {
MessageBox.Show(ex.Message);
}
}
void ComboBox1SelectionChangeCommitted(object sender, EventArgs e)
{
try {
Workbook workbook = new Workbook();
workbook.LoadFromFile(@"E:\ABC\bill_consumables.xlsx");
Worksheet sheet = workbook.Worksheets[0];
CellRange[] crs = sheet.Rows[0].Cells;
foreach (CellRange cr in crs)
{
if (!String.IsNullOrEmpty(cr.Value2.ToString()))
{
comboBox2.Items.Add(cr.Value);
}
}
comboBox2.Items.Remove(comboBox1.Text);
} catch (Exception ex) {
MessageBox.Show(ex.Message);
}
}