【问题标题】:Combobox cell value data source datagridview组合框单元格值数据源datagridview
【发布时间】:2013-10-30 18:01:56
【问题描述】:

在图片下方,我将 Reason 作为具有三个选项的组合框。 在选择第一个值时,例如 In house Rework,第二列责任方是 组合框也应该填充列表集合等 来自原因组合框的另一个值 责任方应填充 另一个列表集合。

由于我已尝试对 gridview 进行最终编辑并且它正在显示值,但如果在下一行我更改了我的返工组合框值,则责任方的先前值不会保留其值。

那么我该如何防止这种情况发生。

感谢您的帮助。

【问题讨论】:

    标签: c# datagridview


    【解决方案1】:

    您是否尝试根据原因中选择的值绑定其他两个组合框?如果是这样,我将在数据网格的事件中使用CellValueChanged 事件,您可以以编程方式构建一个列表并对其进行数据绑定。如果这是您想要做的,我会在这里发布一个示例,如果不是,请澄清,以便我可以提供帮助。

    Private Sub dgVendors_CellValueChanged(sender As System.Object, e As System.Windows.Forms.DataGridViewCellEventArgs) Handles dgVendors.CellValueChanged
    
            If dgVendors.Columns(e.ColumnIndex).HeaderText = "Reason" Then
    
                CType(dgVendors.Rows(e.RowIndex).Cells(""), DataGridViewComboBoxCell).DataSource = Nothing
                CType(dgVendors.Rows(e.RowIndex).Cells(""), DataGridViewComboBoxCell).DisplayMember = ""
                CType(dgVendors.Rows(e.RowIndex).Cells(""), DataGridViewComboBoxCell).ValueMember = ""
    
            ElseIf dgVendors.Columns(e.ColumnIndex).HeaderText = "Responsible Party" Then
    
                CType(dgVendors.Rows(e.RowIndex).Cells(""), DataGridViewComboBoxCell).DataSource = Nothing
                CType(dgVendors.Rows(e.RowIndex).Cells(""), DataGridViewComboBoxCell).DisplayMember = ""
                CType(dgVendors.Rows(e.RowIndex).Cells(""), DataGridViewComboBoxCell).ValueMember = ""
    
            End If
    
    End Sub
    

    【讨论】:

      【解决方案2】:

      如果要处理下拉菜单的选择更改事件,可以handle the EditingControlShowing event of the DataGridView

      还有an MSDN page 可以帮助您。 另外,请确保更改CurrentRowDataGridViewComboBoxCellDataSource,而不是DataGridViewComobBoxColumn

      【讨论】:

        猜你喜欢
        • 2012-02-28
        • 1970-01-01
        • 2018-09-21
        • 2012-03-23
        • 2018-12-31
        • 1970-01-01
        • 2013-09-10
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多