根据项目显示成员向组合框列表项添加不同的颜色

时间:2017-05-06 09:39:14

标签: c# winforms combobox

将我的组合框与来自Db的所选项目绑定如下

   DataTable Dt = CashCounterCls.GetAllCashCounterAll();           
            cmbcashcounter.DataSource = Dt;
            cmbcashcounter.ValueMember = "Counter_Id";
            cmbcashcounter.DisplayMember = "FullName";

我需要根据组合框中包含的文字更改组合框中显示项目的颜色。 即,如果它包含“打开”文本,我需要以绿色显示该列表项

1 个答案:

答案 0 :(得分:-1)

填充组合框后,您可以检查每个项目并转换其颜色。

您可以尝试以下代码,

For Each i As ListViewItem In cmbcashcounter.Items
            If (i.Text = "open") Then
                i.ForeColor = Color.Green
            End If

 Next