簡體   English   中英

如何獲取組合框中的索引值?

[英]How to get the index value in combo box?

public class CustomComboItem
{
    public Double CodeValue { get; set; }
    public String DisplayName { get; set; }
    public String Description { get; set; }
  }

for (int i = 0; i < locCnt; ++i)
 { //I am setting member variable of  CustomComboItem
   // and add to the combobox
   ComboBox1.Items.Add(customComboItem1);
 }

因此,如果需要按CodeValue搜索,如何獲取comboBox的索引。

使用foreach

Int i = 0;

foreach(var item in myComboBox.Items)
{
    if(item.CodeValue = SearchCodeValue)
    {
        return i  // result index
    }
    else
    {
        i = i + 1;
    }
}

你可以試試:

var index = Array.FindIndex<CustomComboItem>(ComboBox1.Items.Cast<CustomComboItem>().ToArray<CustomComboItem>(), item => item.CodeValue == SearchCodeValue);

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM