代码中的错误突出显示某些字段DataGridView

时间:2013-02-08 19:54:41

标签: c#

我从C#.NET中的组合框向DB提交信息,我希望DataGridView中的信息特殊示例(COST)以高光的形状显示。请查看附带的代码。

我正在使用程序代码但是在uni代码中出错,错误:找不到列名,但是在DB框中使用组合框命名字段!

 private void cmb_estekhdam_driver_SelectedIndexChanged(object sender, EventArgs e)
 {
      Color col = Color.Empty;
      string n_estekhdam = null;

        switch (cmb_estekhdam_driver.SelectedItem.ToString())
        {
            case "Daem":

                col = Color.GreenYellow;
                n_estekhdam = "Daem";
                break;
            case "Gharar":
                col = Color.GreenYellow;
                n_estekhdam = "Gharar";
                break;
            case "Rooz":
                col = Color.GreenYellow;
                n_estekhdam = "Rooz";
                break;
        }

        this.DGV_driver.ClearSelection();
        this.PaintRows(col, n_estekhdam);
    }

    private void PaintRows(Color backColor, string n_estekhdam)
    {
       foreach (DataGridViewRow row in DGV_driver.Rows)
        {
            if (row.Cells["estekhdam"].Value.ToString() == n_estekhdam)
            {
                row.DefaultCellStyle.BackColor = backColor;
            }
            else
            {
                row.DefaultCellStyle.BackColor = Color.WhiteSmoke;
            }
        }
    }

0 个答案:

没有答案