c# - 如果包含一些字符串,则隐藏 ComboboxItem
问题描述
如果包含一些特定的字符串,有没有办法折叠或隐藏一些 ComboBoxItems?
我在尝试
foreach (ComboBoxItem b in cboServers.Items)
{
if (b.Content.ToString().Contains("prod"))
{ b.Visibility = Visibility.Visible; }
else
{ b.Visibility = Visibility.Collapsed; }
}
但不起作用,因为 ComboBoxItem 无法转换为字符串
//Read file's content.
foreach (IniSection ContainerForThisServer in iniFile.Sections)
{
cboServidores.Items.Add(ContainerForThisServer.Name.ToUpper());
FillTab(ContainerForThisServer.Name.ToUpper(), ContainerForThisServer);
}
解决方案
您的代码不起作用,因为您正在添加大写项目,并且您的 if 语句检查小写“prod”,但为什么不阻止项目进入组合框?
foreach (IniSection ContainerForThisServer in iniFile.Sections)
{
if (b.Content.ToString().Contains("prod"))
{
cboServidores.Items.Add(ContainerForThisServer.Name.ToUpper());
FillTab(ContainerForThisServer.Name.ToUpper(), ContainerForThisServer);
}
}
推荐阅读
- c# - 使用 HTTPClient 更改 XML 中的文本
- vb.net - 将项目从一个列表框转移到另一个列表
- ide - 无法在 Rubymine 中搜索文件或字符串
- java - 将鼠标位置计算到 3d 空间 - OpenGL
- sql-server - 将 varbinary 加密列中的日期转换回日期
- angular - 如何在 NFC 标签上书写?(离子)
- angular - 如何向密码表单字段添加必须至少为 4 个字符的条件,否则会出错
- kubernetes - 如何确定是否有任何 k8s 资源正在使用特定的 ConfigMap?
- if-statement - 在 Blazor Server 中,如何使用 @if 有条件地显示导航链接?
- python - Python3 - 将 bash 脚本的输出返回到变量