本文介绍了检索组合框的项目的索引的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想检索组合框中包含的项目的索引。



例如



comboBox_dept中填充了数据库中的项目one,two,three





i需要找到他们的索引pro-语法上的。



i试过这个



i want to retrieve Index of the items contained in a combobox.

for eg

comboBox_dept is populated with items from database as "one","two","three"


i need to find their indexes pro-grammatically.

i tried this

int  index = comboBox_dept.FindString(one);
       comboBox_dept.SelectedIndex = index;



它总是返回-1。




it always return -1.

foreach (Object item in comboBox_dept.Items)
               {
                  int index1 = comboBox_dept.Items.IndexOf(item);
               MessageBox.Show(index1.ToString() + item);
               }





它只返回第一项



任何帮助或提示将不胜感激。



it only return 1st item only

any help or hint would be appreciated.

推荐答案



 Public Function GetTextDataGridView(ByVal DataGR As DataGridView, ByVal Rowget As Integer) As String

    GetTextDataGridView = vbNullString
    Try
        Dim i As Integer
        i = DataGR.CurrentRow.Index
        GetTextDataGridView = DataGR.Item(Rowget, i).Value
    Catch ex As Exception

    End Try

End Function




$ _ $ b in Form_Load()





in Form_Load()

Dim item As Object = GetTextDataGridView(frmListMembers.dgvListMember, 3)
Dim Index1 As Integer = cboSex.Items.IndexOf(item)
cboSex.SelectedIndex = Index1


这篇关于检索组合框的项目的索引的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-12 12:44