【问题标题】:How to reset DatagridView Combo box cell On the DatagridView Combo Box SelectedIndexChanged change event如何在 DatagridView 组合框 SelectedIndexChanged 更改事件上重置 DatagridView 组合框单元格
【发布时间】:2011-07-22 08:32:10
【问题描述】:

“这都是关于当我更改另一个数据网格组合框单元格时重置数据网格视图组合框单元格”

示例 :: 如果我在 DataGridView 中有四行,它们都包括组合框 如果我在所有这些中选择值 我只是更改任何组合框单元格的第一行中的值,因此相应的事件应该从他的位置重置下面的所有单元格

有可能吗!或任何建议

【问题讨论】:

  • 如果它是第二行,那么应该重置第一行怎么办?它是否意味着应该只出现所有 ComboBox 被选中的一行?
  • 在这种情况下,第三和第四行单元格将被重置,我的意思是重置流程是从上到下

标签: c# datagridviewcomboboxcell


【解决方案1】:
private void Grid_ComboBox_SelectedIndexChanged(object sender, EventArgs e)
{
    int X_access = -1;
    int Y_access = -1; 

    // Reset DatagridView ComboBox cell On the DatagridView ComboBox
    if (dataGridView_preView.CurrentCell.RowIndex == 0)
    {
        X_access = dataGridView_preView.CurrentCellAddress.Y; // find Cell position 
        Y_access = dataGridView_preView.CurrentCellAddress.X;
        dataGridView_preView.Rows[X_access + 1].Cells[Y_access].Value = ""; // reset
        dataGridView_preView.Rows[X_access + 2].Cells[Y_access].Value = "";
        dataGridView_preView.Rows[X_access + 3].Cells[Y_access].Value = "";
    }

    else if (dataGridView_preView.CurrentCell.RowIndex == 1)
    {
        dataGridView_preView.Rows[X_access + 1].Cells[Y_access].Value = "";                  
        dataGridView_preView.Rows[X_access + 2].Cells[Y_access].Value = "";
    }
    else if (dataGridView_preView.CurrentCell.RowIndex == 2)
    {
    }
    else if (dataGridView_preView.CurrentCell.RowIndex == 3)
    {
    }
}

【讨论】:

  • 希望对你有帮助我也试试这个
【解决方案2】:
foreach (Control field in container.Controls)
{
    if (field is ComboBox)
        ((ComboBox)field).SelectedIndex = 0;
    else
        dgView.DataSource = null;
        ClearAllText(field);
}

它会重置它们的初始位置

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2012-11-06
    • 1970-01-01
    • 1970-01-01
    • 2018-09-21
    • 1970-01-01
    • 2021-02-20
    • 1970-01-01
    • 2018-12-31
    相关资源
    最近更新 更多