private void FilterListBox_Load(object sender, EventArgs e) { SqlConnection cn = new SqlConnection("Data Source=SRISTI;Initial Catalog=Anjanee;Integrated Security=True"); SqlDataAdapter da = new SqlDataAdapter("select UserName from User_Name", cn); DataSet ds = new DataSet(); da.Fill(ds, "ABC"); int count = ds.Tables[0].Rows.Count; for (int i = 0; i < count; i++) { listBox1.Items.Add(ds.Tables[0].Rows[i]["UserName"].ToString()); } }
private void textBox1_TextChanged(object sender, EventArgs e) { foreach (string s in listBox1.Items) { if (s.StartsWith(textBox1.Text) == true) { listBox1.SelectedItem = s; } } }
Quote:foreach (string s in listBox1.Items) { if (s.StartsWith(textBox1.Text) == true) { listBox1.SelectedItem = s; } }
for(int i=0; i<listbox1.items;> { if (listBox1.items[i].StartsWith(textBox1.Text) == true) { listBox1.SelectedIndex = i; } }
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)