2011-12-20 96 views
1

我正在創建一個應用程序來從列表框中搜索用戶鍵入的單詞。我想只顯示列表框中與用戶鍵入的字符匹配的項目。我無法找到確切的語法。如何訪問所有列表框項目的索引?

private void textBox1_TextChanged(object sender, EventArgs e) 
    { 
     string a=textBox1.Text; 
     for (int i = 0; i < listBox1.Items.Count; i++) 
     { 
      if(a[0]==listBox1.Items(i).char[0])//how to do this? 
        {........ 
        } 

     } 
    } 
+0

指數接入使用[] – MethodMan 2011-12-20 15:16:29

+0

@RabbiaAnnum - 修復你的代碼。 – 2011-12-20 15:51:11

回答

1

,如果你想查詢的做這樣的事情 也煤焦如果你沒有得到「文本/字符串值..添加的ToString(); listBox1.Items後[1]。的ToString();

if(a[i]== listBox1.Items[i]) 
{ 
    //i is the incremented value here.. 
} 

foreach (char valchar in a) 
{ 
    // do your logic.. 'X' single quotes for Char 
} 

if you want to check for a string in a do 

foreach (string valString in a) 
{ 
    // do your logic for a string check if valString = "X" for example "" double quotes for 
} 
0

像這樣:在C#

string a = textBox1.Text; 
for (int i = 0; i < listBox1.Items.Count; i++) 
{ 
    if(a[0] == listBox1.Items[i].Text) 
    { 
      //Do Something... 
     } 
} 
相關問題