【问题标题】:Updating ComboBox Column in datagridview更新 datagridview 中的组合框列
【发布时间】:2016-10-25 07:39:42
【问题描述】:

我正在使用以下代码填充我的 datagridview。

dgvPChannel.AutoGenerateColumns = true;
        dgvPChannel.DataSource = new PaymentsAccess().getAllComplianceAccounts().ToList();

我在 datagridview 中创建了一个额外的列并填充了这个组合框列。当将此组合框更改为选项和“更新”按钮时,我现在需要更新我的数据库。如何使用为每个项目选择的组合框选项更新我的所有 datagridview 项目。

【问题讨论】:

    标签: c# datagridview combobox


    【解决方案1】:

    如果循环遍历网格中的每个 ComboBox 值,则可以更新选中的行。检查这个:

       private void btnUpdate_Click(object sender, EventArgs e)
        {
             
            foreach (DataGridViewRow row in yourdataGridView.Rows)
            {
                var comboValue = string.IsNullOrEmpty(row.Cells[ComboBoxColumnName.Index].Value.ToString()) ? "" : row.Cells[ComboBoxColumnName.Index].Value.ToString();
                if (some logic here to update)
                {
                    //update your_table set field = value where id = row.Cells["fieldname"].Value;
                   
    
                }
            }
    
        }
    

    【讨论】:

    • 它是一个组合框而不是复选框
    • 好的,非常感谢你,我会努力让你知道,我如何设置我的组合框选定项目。例如,如果 row.cells[1].value == "A" 组合框 selectedindex 1。请帮忙?
    • 没关系从这里得到我的答案 - stackoverflow.com/questions/4825222/…
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-07-24
    相关资源
    最近更新 更多