按另一个属性的值过滤属性

时间:2014-12-12 16:58:03

标签: c# list devexpress filtering xaf

我有两个下拉列表。他们中的其他人彼此有关系。但我需要根据另一个下拉列表的选择值过滤一个下拉列表。

我可以在代码中过滤它。当我调试时,我可以在属性上看到过滤结果。但是,当我运行应用程序时,它不起作用。到目前为止,这是我的代码:

    private BindingList<Commodity> _AllocationCommodities;
    [Browsable(false)]
    public BindingList<Commodity> AllocationCommodities
    {
        get
        {
            if (_AllocationCommodities == null)
            {
                _AllocationCommodities = new BindingList<Commodity>();
                ChangeCommodities();
            }
            return _AllocationCommodities;
        }
    }
    private SourceEntity _SourceEntity;
    [ImmediatePostData]
    [Association("SourceEntity-LimitAllocations")]
    [RuleRequiredField("RuleRequiredField_LimitAllocation_SourceEntity", DefaultContexts.Save)]

    public SourceEntity SourceEntity
    {
        get
        {
            return _SourceEntity;
        }
        set
        {    

            //New Code
            if (SetPropertyValue<SourceEntity>("SourceEntity", value))
            {
                if (IsSaving || IsLoading) return;
                ChangeCommodities();
            }
        }
    }
    private Commodity _Commodity;// This is the drop down to be filtered
    [ImmediatePostData]
    [DataSourceProperty("AllocationCommodities")] //// This Attribute Should filter Commodities                 
    [RuleRequiredField("RuleRequiredField_LimitAllocation_Commodity", DefaultContexts.Save)]
    public Commodity Commodity
    {
        get
        {
            return _Commodity;
        }
        set
        {
            SetPropertyValue("Commodity", ref _Commodity, value);
            if (Commodity.Oid != Guid.Empty)
                AllocationVolumeUnits.Reload();
        }
    }
    private void ChangeCommodities()
    {
        if (!this.IsLoading && _SourceEntity != null)
        {
            _AllocationCommodities.RaiseListChangedEvents = false;
            _AllocationCommodities.Clear();
            OperandValue[] _params;
            System.Collections.Generic.List<CMSBOD.SourceCommodity> _sc = new System.Collections.Generic.List<SourceCommodity>();

            BindingList<Commodity> _Commodities = new BindingList<Commodity>();

            foreach (SourceCommodityEntity _tempSCE in _SourceEntity.SourceCommodityEntities)
            {
                if (_tempSCE.SourceCommodity != null)
                    _sc.Add(_tempSCE.SourceCommodity);
            }
            foreach (SourceCommodity _tempSC in _sc)
            {
                if (_tempSC.Commodity != null && !_Commodities.Contains<Commodity>(_tempSC.Commodity) && _tempSC.Commodity.IsActive)
                    _Commodities.Add(_tempSC.Commodity);
            }
            _AllocationCommodities.RaiseListChangedEvents = true;
            _AllocationCommodities = _Commodities;///This is where I can see the filtered list when debugging.


        }
    }

1 个答案:

答案 0 :(得分:1)

您可以在此方案中找到有用的DataSourceCriteria,而不是DataSourceProperty。

假设您拥有将商品关联回SourceCommodityEntity的集合属性,您可以使用以下条件:

[DataSourceCriteria(“IsActive和SourceCommodities [SourceCommodityEntities [SourceEntity ='@ SourceEntity']]”)]

即使它被设计为1x1关联,您也可以发现关联对于过滤目的非常有用。