[ENG] ComboBox problem
-
sorry for posting in english ... but this is the only decent forum i found to post this problem....
it's about dynamic searching using a ComboBox
if we have let's say 4 entrys
AB C
AB CD
AB D
AB DE
and we enter "AB" into the ComboBox, the goal is to get all 4 as an option
then if we change it to "AB C", the goal is to get just the two -> "AB C" and "AB CD"....here's my synthax :
(using a TextChanged event handler on the declaration of the combobox)
.........this->myComboBox->TextChanged += gcnew System::EventHandler (this, &Form1::myHandlerFunction); ..................... System::Void myHandlerFunction(System::Object^ sender, System::EventArgs^ e) { String ^query = myComboBox->Text::get(); cmd->CommandText="SELECT ......."; // sending here a query to DB to get the results cmd->CommandType=CommandType::Text; SqlDataReader ^rd; rd=cmd->ExecuteReader(); while(rd->Read()==true){ if(myComboBox->Items->Contains(rd->GetString(0)) == false) myComboBox->Items->Add(rd->GetString(0)); } rd->Close(); delete rd; }
now... as you can see, i'm adding every entry that isn't contained in the combobox, but logicaly, that doesn't give the desired goal (after writing "AB C" , the combobox still contains "AB D" and "AB DE" entrys)
for this matter, i tryed using myComboBox->Items->Clear();
which would clear the combobox on every new entry, but this results in re-setting the writting cursor, which isn't effective...
i also tryed running a for loop using - myComboBox->Items->RemoveAt(i);
which also gave some index-problems....another problem, is that the combobox has some lame autocomplete-ing feature (which i set to NONE in properties),
firstly , it doesnt drop down automaticaly, providing the options (for choosing with arrows or mouse), secondly, after clicking the drop down button it automaticly selects the first item in the list.... :Sany thoughts are MOST welcome.... thnx to anyone who's taken time to read...
-
actually i didn't quite get what you mean. if you want an autocomplete feature based on what you already typed into your combobox, you can just set the following properties:
- AutoCompleteMode = Suggest;
- AutoCompleteSource = ListItems;
this works for me. if this isn't what you're looking for, you should probably explain the thing with this SQL-style database access.
:xmas1:
-
thnx for answering !!
looks like
AutoCompleteSource = ListItems;solved both problems
thnx very much ! :xmas2: