public System.Data.DataView CreateChildView(DataRelation relation)
        {
            if ((relation == null) || (relation.ParentKey.Table != this.DataView.Table))
            {
                throw ExceptionBuilder.CreateChildView();
            }
            int record = this.GetRecord();

            object[]    keyValues = relation.ParentKey.GetKeyValues(record);
            RelatedView view      = new RelatedView(relation.ChildColumnsReference, keyValues);

            view.SetIndex("", DataViewRowState.CurrentRows, null);
            view.SetDataViewManager(this.DataView.DataViewManager);
            return(view);
        }
Esempio n. 2
0
        /// <summary>
        /// Returns a <see cref="System.Data.DataView"/>
        /// for the child <see cref="System.Data.DataTable"/>
        /// with the specified <see cref="System.Data.DataRelation"/>.
        /// </summary>
        /// <param name="relation">Specified <see cref="System.Data.DataRelation"/>.</param>
        /// <exception cref="ArgumentException">null or mismatch between <paramref name="relation"/> and <see cref="System.Data.DataView.get_Table"/>.</exception>
        public DataView CreateChildView(DataRelation relation, bool followParent)
        {
            if (relation == null || relation.ParentKey.Table != DataView.Table)
            {
                throw ExceptionBuilder.CreateChildView();
            }
            RelatedView childView;

            if (!followParent)
            {
                int      record = GetRecord();
                object[] values = relation.ParentKey.GetKeyValues(record);
                childView = new RelatedView(relation.ChildColumnsReference, values);
            }
            else
            {
                childView = new RelatedView(this, relation.ParentKey, relation.ChildColumnsReference);
            }
            childView.SetIndex("", DataViewRowState.CurrentRows, null); // finish construction via RelatedView.SetIndex
            childView.SetDataViewManager(DataView.DataViewManager);
            return(childView);
        }