【问题标题】:Getting the value of a datagridview to a combobox. C#将 datagridview 的值获取到组合框。 C#
【发布时间】:2014-05-07 01:07:30
【问题描述】:

我想做的事情是从已经填充的 datagridview 表中获取值,进入编辑阶段,文本框填充得很好,但我找不到将表的值分配给组合框项的方法。

private void button2_Click(object sender, EventArgs e) 
    {                                                      
        DataGridViewRow cliente = dataGridView1.CurrentRow;
        textBoxDsClave.Text = cliente.Cells["dsClave"].Value.ToString();
        textBoxDsRazonSocial.Text = cliente.Cells["dsRazonSocial"].Value.ToString();
        comboBoxCnAceptaPromociones = cliente.Cells["cnAceptaPromociones"].Value.ToString(); //THIS ONE
    }

额外信息,“cnAceptaPromociones”的数据类型是bool,所以它只有“true”或“false”。

我真的是 C# 的新手,而且我很难学习。

【问题讨论】:

    标签: c# winforms datagridview combobox


    【解决方案1】:

    尝试设置SelectedValue 属性:

    comboBoxCnAceptaPromociones.SelectedValue =
        Convert.ToBoolean(cliente.Cells["cnAceptaPromociones"].Value);
    

    【讨论】:

    • 按我的需要工作,谢谢格兰特。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-08-28
    • 1970-01-01
    • 1970-01-01
    • 2015-05-28
    • 2014-05-29
    • 2012-01-10
    相关资源
    最近更新 更多