如何查找和替换组合框中的项
How to find and replace an items in a ComboBox
在c++ Builder XE8中,我使用以下方法将项插入到组合框中:
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();
我想知道如何将第3项127.0.0.1替换为xxx.0.0.1。我试过使用StringReplace()
,但没有运气。
首先,您的示例应该使用Add()
而不是Insert()
(以及try/__finally
块或RAII包装器,以防抛出异常):
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();
}
现在,话虽如此,如果你知道你想要更改的项目总是第四个项目,那么只需直接更新它:
MyComboBox->Items->Strings[3] = "xxx.0.0.1";
如果你需要搜索它,使用IndexOf()
:
int index = MyComboBox->Items->IndexOf("127.0.0.1");
if (index != -1)
MyComboBox->Items->Strings[index] = "xxx.0.0.1";
相关文章:
- 模板参数替换失败,并且未完成隐式转换
- 如何在OMNET++中指定与命令行参数组合的输出文件名
- 可组合的lambda/std::函数与std::可选
- 如何用转义符替换字符串中的所有特殊字符
- 如何将两个不同矢量的同一位置的两个元素组合在一起
- 混合组合和继承的C++问题
- 我需要将多个函数组合为一个函数
- 构建可组合有向图(扫描仪生成器的汤普森构造算法)
- 为什么除非添加括号,否则构造函数上的模板替换会失败?
- 通过组合不同的类型来创建唯一的id
- 用常见虚拟函数实现的任意组合来实现派生类的正确方法是什么
- 在一个读写器队列中,我可以用volatile替换原子吗
- 模板元编程:如何将参数包组合成新的参数包
- 用符号版本替换对函数的所有调用
- 检查向量是否具有所有可能的字符组合
- 如何通过替换顺序代码的while循环来添加OpenMP for循环
- 替换基于地图的所有引用
- 以几种组合替换
- 组合或替换多个相似的重载
- 如何查找和替换组合框中的项