根据特定行

时间:2017-02-16 09:14:42

标签: c# winforms datagrid infragistics

private void dgGrid_CellListSelect(object sender, CellEventArgs e)
{
    if (e.Cell.Column.Key == "ColumnA")
    {
        UltraGridRow selectedItem = ((UltraCombo)e.Cell.EditorControlResolved).SelectedRow;

        if (selectedItem != null)
        {
            //Option A
            cmbColumnB.DataSource = GetUISender<someBF>().RetrieveData(dataset).dataTable;
            cmbColumnB.DataBind();

            //Option B
            //((UltraCombo)e.Cell.Row.Cells["ChipSetID"].EditorControlResolved).DataSource = GetUISender<someBF>().RetrieveData(dataset).dataTable;
        }

    }
}

有一个按钮允许数据网格添加新行。 此数据网格有2列,两列都是UltraComboColumnB组合框的dataSource将基于ColumnA。基于上面的代码,如果datagrid只有1行,它就可以工作,但是一旦用户添加了另一行,两行ColumnB将共享同一个DataSource。

如何确保ColumnB的DataSource独立保留而不影响其他行?很明显,这是因为每一行共享相同的组件cmbColumnB,但我不确定如何删除引用

1 个答案:

答案 0 :(得分:0)

我找到了解决方案,每次创建一个新的UltraCombo并将其绑定到特定单元格的EditorControl

private void dgGrid_CellListSelect(object sender, CellEventArgs e)
{
    if (e.Cell.Column.Key == "ColumnA")
    {
        UltraGridRow selectedItem = ((UltraCombo)e.Cell.EditorControlResolved).SelectedRow;

        if (selectedItem != null)
        {
            UltraCombo cmbValue = new UltraCombo();
            cmbValue.LimitToList = true;
            cmbValue.DropDownStyle = UltraComboStyle.DropDownList;
            cmbValue.DataSource = GetUISender<someBF>().RetrieveData(dataset).dataTable;
            cmbValue.ValueMember = someDS.someDT.someColumnIDColumn.ColumnName;
            cmbValue.DisplayMember = someDS.someDT.someColumnDescriptionColumn.ColumnName;
            cmbValue.BindingContext = someDg.BindingContext;
            cmbValue.DataBind();
            e.Cell.Row.Cells["ColumnB"].EditorControl = cmbValue;
            e.Cell.Row.Cells["ColumnB"].Style = Infragistics.Win.UltraWinGrid.ColumnStyle.DropDownList;

        }

    }
}