c++ - How to find and replace an items in a ComboBox -
in c++ builder xe8, i'm using following methods insert item combobox:
mycombobox->items->beginupdate(); mycombobox->items->insert(0, "title"); mycombobox->items->insert(1, "google"); mycombobox->items->insert(2, "yahoo"); mycombobox->items->insert(3, "127.0.0.1"); mycombobox->itemindex = 0; mycombobox->items->endupdate();
i want know how replace 3rd item, 127.0.0.1, "xxx.0.0.1". i've tried using stringreplace()
, no luck.
first, example should using add()
instead of insert()
(and try/__finally
block or raii wrapper, in case exception thrown):
mycombobox->items->beginupdate(); try { mycombobox->items->add("title"); mycombobox->items->add("google"); mycombobox->items->add("yahoo"); mycombobox->items->add("127.0.0.1"); mycombobox->itemindex = 0; } __finally { mycombobox->items->endupdate(); }
now, said, if know item want change fourth item, update directly:
mycombobox->items->strings[3] = "xxx.0.0.1";
if need search it, use indexof()
:
int index = mycombobox->items->indexof("127.0.0.1"); if (index != -1) mycombobox->items->strings[index] = "xxx.0.0.1";
Comments
Post a Comment