private void comboBox1_SelectedIndexChanged(object sender, EventArgs e) { this.btnOK.Enabled = ((this.comboBox1.SelectedIndex >= 0) && (this.cboX.SelectedIndex >= 0)) && (this.cboY.SelectedIndex >= 0); if (this.comboBox1.SelectedIndex >= 0) { List <string> excelColumns = ExcelTools.GetExcelColumns(this.textBox1.Text, this.comboBox1.Text); for (int i = 0; i < excelColumns.Count; i++) { this.cboX.Items.Add(excelColumns[i]); this.cboY.Items.Add(excelColumns[i]); } if (this.cboX.Items.Count > 0) { this.cboX.SelectedIndex = 0; this.cboY.SelectedIndex = 0; } if (this.cboX.Items.Count > 1) { this.cboY.SelectedIndex = 1; } } }