I am creating a program , some words just like dictionary, items (words) are in combobox. You select word in combobox and explanation of that word you select appears in label. Later i was trying to make search, i create that, bus is problem. That is just like live search, then you are typing word, program automaticly in label says "no match found" , then you finish - in label appear if that word is. How to do that : you write word in combobox and then push for example ENTER, and then program if word is - explanation of that word, if not - "no match found".
code is :
private void cmb_b1_TextChanged(Object sender, System.EventArgs e)
{
int pos = 0;
boolean found = false;
for (int i = 0; i < word.length; i++) {
if(explanation
.compareTo(cmb_b1.get_Text()) == 0) {
pos = i;
found = true;
break;
}
}
if (found == true)
lbl_desc.set_Text(explanation[pos]);
else
lbl_desc.set_Text("No Mach found");
}
search in combobox by pressing button
John Sudds - MSFT
Hi,
If I understand the question correctly, this is what you are trying to do.
You have a list of items in a combo box & and a label.
When you start typing in the combo box and the characters match an item in the combo box , the item's explanation is to be displayed in the label.
In the code you have mentioned
if(explanation
you are comparing the explanation to the combo box text, you need to compare word
instead.
I have pasted a sample code.
private void comboBox1_TextUpdate(Object sender, System.EventArgs e)
{
int pos = 0;
boolean found = false;
String explanation[];
explanation = new String[3];
explanation[0] = "Apple a day, keeps doctor away";
explanation[1] = "Orange keeps you young looking";
explanation[2] = "Banana helps digest your food intake";
String word[];
word = new String[3];
word[0] = "Apple";
word[1] = "Orange";
word[2] = "Banana";
for (int i = 0; i < 3; i++)
.compareTo(comboBox1.get_Text()) == 0)
{
if (word
{
pos = i;
found = true;
break;
}
}
if (found == true)
label1.set_Text(explanation[pos]);
else
label1.set_Text("No Mach found");
}
Note: make sure you have added the function as event handler
I have added the combo box and lable in a windows form. In the InitializeComponent() add
this.comboBox1.add_TextChanged(new System.EventHandler(this.comboBox1_TextUpdate));
Please mail back if your requirement is different.
Thanks,
Shiva.
SQLHelp
In my program, the arrays are not in combobox selected change event.
I write all code where is it. I need to rewrite in that event
Rhodry
Hi,
If you want to do live search like functionality, your current code in Text Changed Event handler is correct except for
the if(explanation[ i ].compareTo(cmb_b1.get_Text()) == 0) . Is 'word' the array you use to store all the dictionary words
If so just change to if(word[ i ].compareTo(cmb_b1.get_Text()) == 0).
Thanks,
Shiva.