1

嗨程序员,实际上我在 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 时会出错。

请帮帮我。

4

2 回答 2

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"



                }
            }
}

最后我的问题解决了。

于 2012-03-30T09:03:33.340 回答
0

尝试这个

Private Sub dgvMain_CellMouseEnter(sender As Object, e As DataGridViewCellEventArgs) Handles dgvMain.CellMouseEnter
        Dim dgv As DataGridView
        dgv = DirectCast(sender, DataGridView)
        If dgv IsNot Nothing Then
            Dim cmb As DataGridViewComboBoxCell 
            cmb = DirectCast(dgv.Rows(e.RowIndex).Cells(e.ColumnIndex), DataGridViewComboBoxCell)
            If cmb IsNot Nothing Then
                cmb.Selected = True
            End If
        End If
    End Sub
于 2022-03-04T22:47:52.177 回答