am new in c# and i have some problems that o need some help
i have t text box that when i type the characters i want a drop down list to be appeard under the text box sorted according the characters that i type.
if i type ont he textbox "myn" the dropdown list to be appeaerd sorted and according the first characters that i write.also this values that are going to be display must be retrieve from a database from sql server.
i try doing something but i find dificulties.
i thing that the problem is in the try statement.i dont know hot to diplay the data.
beside that i don't know if the mylistboxitem is correct.
the values that are going to be display are vchar.
i have t text box that when i type the characters i want a drop down list to be appeard under the text box sorted according the characters that i type.
if i type ont he textbox "myn" the dropdown list to be appeaerd sorted and according the first characters that i write.also this values that are going to be display must be retrieve from a database from sql server.
i try doing something but i find dificulties.
Code:
class MyListBoxItem { public MyListBoxItem(int ItemData, string Text) { text = Text; itemData = ItemData; } public int ItemData { get { return itemData; } set { itemData = value; } } public override string ToString() { return text.Trim(); } protected string text; protected int itemData; } private void textBox1_TextChanged(object sender, EventArgs e) { if (capturesymptom.Text.Length > 1) { SearchName(); } } private void SearchName() { ListBox ListBox1 = new ListBox(); ListBox1.Items.Clear(); SqlConnection dataConnectionSymptom = null; DataSet datasetsymptom = null; //connection with the database// SqlDataAdapter dataAdaptersymptom = new SqlDataAdapter(querysymptom); dataAdaptersymptom.Fill(datasetsymptom, "[Symptoms]"); datasetsymptom.DataSetName = "[DiseaseName]"; dataConnectionSymptom.Close(); for (int i = 0; i < datasetsymptom.Tables["[Symptoms]"].Rows.Count; i++) { ListBox1.Items.Add(new MyListBoxItem(Convert.ToInt32(datasetsymptom.Tables["Symptoms"].Rows[i][0].ToString()),datasetsymptom.Tables["Symptoms"].Rows[i][1].ToString())); } try { //i thing the problem is in this step.i don't know how i should diplay the data that i get from the database under my text box } catch { MessageBox.Show("search failed"); } finally { dataConnectionSymptom.Close(); } }
beside that i don't know if the mylistboxitem is correct.
the values that are going to be display are vchar.
Comment