2011-03-17 2 views
0

자동 완성 텍스트 상자 검색을 구현할 수 있지만 대소 문자를 구분합니다. 나는 그것을 둔감하게 만들어주고 싶다. 나는 또는 조건을 넣었지 만 처음 입력 한 편지 만 검사합니다. 나는 검색이 대소 문자를 구분하지 않기를 바란다.Dotnet : - 자동 완성 텍스트 상자의 대소 문자를 구분하지 않으려면 어떻게합니까?

다음은 내 코드

public partial class Form1 : Form 
{ 
    AutoCompleteStringCollection acsc; 
    public Form1() 
    { 
     InitializeComponent(); 
     acsc = new AutoCompleteStringCollection(); 
     textBox1.AutoCompleteCustomSource = acsc; 
     textBox1.AutoCompleteMode = AutoCompleteMode.None; 
     textBox1.AutoCompleteSource = AutoCompleteSource.CustomSource; 
     acsc.Add("Sim Vodafone"); 
     acsc.Add("sim vodafone"); 
     acsc.Add("sIm"); 
     acsc.Add("siM"); 
    } 

    private void textBox1_TextChanged(object sender, EventArgs e) 
    { 
     string d = null; 

     listBox1.Items.Clear(); 
     if (textBox1.Text.Length == 0) 
     { 
      hideResults(); 
      return; 
     } 
     foreach (String s in textBox1.AutoCompleteCustomSource) 
     { 
      d = textBox1.Text.ToUpper(); 
      if (s.Contains(d) || s.Contains(textBox1.Text)) 
      { 
       Console.WriteLine("Found text in: " + s); 
       listBox1.Items.Add(s); 
       listBox1.Visible = true; 
      } 
     } 
    } 

    private void listBox1_SelectedIndexChanged(object sender, EventArgs e) 
    { 
     textBox1.Text = listBox1.Items[listBox1.SelectedIndex].ToString(); 
     hideResults(); 
    } 

      void listBox1_LostFocus(object sender, System.EventArgs e) 
    { 
     hideResults(); 
    } 

    void hideResults() 
    { 
     listBox1.Visible = false; 
    } 
} 

}

답변

2

유일한 생각은 autoCompleteSource의 문자열을 upper로 변환하는 것입니다.

d = textBox1.Text.ToUpper(); 
if (s.Contains(d) || s.Contains(textBox1.Text)) 
{ 
    Console.WriteLine("Found text in: " + s); 
    listBox1.Items.Add(s); 
    listBox1.Visible = true; 
} 

d = textBox1.Text.ToUpper(); 
string upperS = s.ToUpper(); 
if (upperS.Contains(d)) 
{ 
    Console.WriteLine("Found text in: " + s); 
    listBox1.Items.Add(s); 
    listBox1.Visible = true; 
} 

에 변경하고 그것을 작동합니다. 자신의 목록 상자를 만드는 것보다 자동 완성에 대한 간단한 솔루션이 있어야한다고 확신합니다.

+0

답변 해 주셔서 감사합니다. 그것은 꽤 simple.Listbox 내가 목적을 위해 만들었습니다. – Prachur

0

이 시도 할 수있다.

d = textBox1.Text; 
    if (s.Contains(d.ToUpper()) || s.Contains(d.ToLower()) || s.Contains(textBox1.Text.ToUpper()) || Contains(textBox1.Text.ToLower())) 
관련 문제