首页 > Windows开发 > 详细

winform datagridview中combobox列改变选项时触发其他列变化

时间:2019-01-29 16:22:08      阅读:167      评论:0      收藏:0      [点我收藏+]

之前想使用DataGridView的SelectionChanged事件,但是使用了后并没有达到效果

最后使用下面的方式实现:

private void materialCheckGridView_EditingControlShowing(object sender, DataGridViewEditingControlShowingEventArgs e)
{
    int cidx = materialCheckGridView.CurrentCell.ColumnIndex;
    if (materialCheckGridView.Columns[cidx].Name == "ColRetMainDefect")
    {
        //还原控件并绑定事件
        ((ComboBox)e.Control).SelectedIndexChanged += new EventHandler(MaterialCheckForm_SelectedIndexChanged);
    }
}

private void MaterialCheckForm_SelectedIndexChanged(object sender, EventArgs e)
{
    int cindex = materialCheckGridView.CurrentRow.Index;
    if (cindex >= 0)
    {
        int idx = materialCheckGridView.CurrentCell.ColumnIndex;
        if (materialCheckGridView.Columns[idx].HeaderText == "回修主要病疵")
        {
            //int cindex = materialCheckGridView.CurrentCell.RowIndex;
            string defdesc = ProdReportDA.GetDefectsDescription(materialCheckGridView.Rows[cindex].Cells["ColRetMainDefect"].EditedFormattedValue.ToString(), materialCheckGridView.Rows[cindex].Cells["RollId"].Value.ToString());
            materialCheckGridView.Rows[cindex].Cells["ColDefectDesc"].Value = defdesc;
        }
    }
}

 

winform datagridview中combobox列改变选项时触发其他列变化

原文:https://www.cnblogs.com/hubbert123/p/10334117.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!