如何在CellContentClick事件中手动选择DataGridviewComboBoxCell值?

时间:2012-03-29 05:07:34

标签: casting datagridviewcomboboxcell

嗨程序员,                 实际上我在DataGridvIew中有一个DataGridViewComboBoxCell,如果在触发CellContentClick事件时条件为真,我需要更改DataGridViewComboBox值。               我的代码就像这样:

    private void gridviewholiday_CellContentClick_1(object sender, DataGridViewCellEventArgs e)
    {
        int row = e.RowIndex;
        int colo = e.ColumnIndex;


        /*=============== To Show The Details  =====================*/

        if (e.ColumnIndex == 4)
        {
            if (Convert.ToBoolean(gridviewholiday.Rows[e.RowIndex].Cells[0].Value))
            {
                if (Type == "CUS")
                {
                    Type = test.colType;
                    if (Type == "NO")
                    {


                        ComboBox combo = (ComboBox)sender;
                        combo.SelectedIndex = 0;

                    }
                }
    }

但是在将DataGridView转换为Combobox时会出错。

请帮帮我。

1 个答案:

答案 0 :(得分:1)

你好朋友!

我得到了答案,我手动选择了DataGridviewComboBoxCell。

private void gridviewholiday_CellContentClick_1(object sender, DataGridViewCellEventArgs e)
{
    int row = e.RowIndex;
    int colo = e.ColumnIndex;


    /*=============== To Show The Details  =====================*/

    if (e.ColumnIndex == 4)
    {
        if (Convert.ToBoolean(gridviewholiday.Rows[e.RowIndex].Cells[0].Value))
        {
            if (Type == "CUS")
            {
                Type = test.colType;
                if (Type == "NO")
                {
                     /*===== set the selected value of comboboxCellItems   ==========*/

                      gridviewholiday.Rows[e.RowIndex].Cells["colType"].Value="ALL"



                }
            }
}

最后我的问题解决了。

相关问题