如何获得combobox.selectedindex值 [英] how to get combobox.selectedindex value

查看:1301
本文介绍了如何获得combobox.selectedindex值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是我的源代码,其中我从excel表单名称填充了我的组合框,但是

i无法获得同一事件的索引值



this is my source code where i populated my combobox from excel sheet sheet name but
i am unable to get value of index on the same event

 private void button5_Click(object sender, EventArgs e)
       {
           OpenFileDialog op = new OpenFileDialog();
           if (op.ShowDialog() == System.Windows.Forms.DialogResult.OK)
           {
               textinput.Text = op.FileName;
           }
Excel.Application xlApp;
           Excel.Workbook xlWorkBook;
           xlApp = new Excel.Application();
           xlWorkBook = xlApp.Workbooks.Open(textinput.Text, 0, true, 5, "", "", true, Microsoft.Office.Interop.Excel.XlPlatform.xlWindows, "\t", false, false, 0, true, 1, 0);
           object misValue = System.Reflection.Missing.Value;
 List<string> sheetname = new List<string>();

           foreach (Microsoft.Office.Interop.Excel.Worksheet wSheet in xlWorkBook.Worksheets)
           {
               sheetname.Add(wSheet.Name);
           }
           comboBox2.DataSource = sheetname;

           xlWorkBook.Close(true, misValue, misValue);
           xlApp.Quit();
           releaseObject(xlWorkBook);
           releaseObject(xlApp);
           }





当我试图通过改变组合下拉来获得combobox2.selectindex时,总是得到0作为同一事件的索引值,有没有办法获得选择索引值

plz help.my combobox正确填充工作表名称,但没有得到索引值???



when i am trying to get combobox2.selectindex by changing combo drop down ,always getting 0 as index value on the same event ,is there any way to get select index value
plz help.my combobox is populating the sheet name correctly,but not getting the index value???

推荐答案

尝试以下操作 -

Try the following -
private void comboBox2_SelectedIndexChanged(object sender, EventArgs e)
{
    ComboBox cmb = (ComboBox)sender;
    int selectedIndex = cmb.SelectedIndex;
    int selectedValue = (int)cmb.SelectedValue;

    ComboboxItem itm= (ComboboxItem)cmb.SelectedItem;
}


这篇关于如何获得combobox.selectedindex值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆