Welcome to the Xceed Community | Help
Community Search  
More Search Options

Master/Detail Row expanded

Sort Posts: Previous Next
  •  05-14-2008, 12:46 PM Post no. 12262

    Master/Detail Row expanded

    Hello,

    What event is triggered when a row is expanded in a Master/Detail Grid so i can refresh the data when i insert a new row so it gets its new primary key from the database in order for the user to add children for the newly added row?

     Thank you
     

  •  05-14-2008, 5:24 PM Post no. 12276 in reply to 12262

    Re: Master/Detail Row expanded

    There is no such event. An option would be to query the DataGridContext.HasDetails property or check if the current item has expanded details by calling the AreDetailsExpanded method.

    A second option would be to create a new DataRow template and hook directly into the detail toggle button. 


    Senior Technical Writer
    - Xceed Software

    In three words I can sum up everything I've learned about life: it goes on.
    Filed under:
  •  03-10-2009, 7:26 PM Post no. 19186 in reply to 12276

    Re: Master/Detail Row expanded

    Could you please post a code sample of this?  I can't make any sense of what objects you are talking about.

    I've read all of the posts on this forum filed under the Master/Detail tag, and have yet to be able to find a solution to my problem.

    The problem is that I have a working Master/Detail grid set up and running.  When a new row is inserted, I cannot find the required API call to retrieve the master object (AKA parent object).  I need the parent object so that I can link the new child object to the parent child object (like a Foreign Key relatonship).

     

  •  03-11-2009, 8:48 AM Post no. 19196 in reply to 19186

    Re: Master/Detail Row expanded

    Have you considered creating a custom detail description? In the GetDetailForParentItem method, you put the required code to get the detail data. Take a look at the example in the documentation: http://doc.xceedsoft.com/products/XceedWpfDataGrid/Custom_Detail_Descriptions.html
    Senior Technical Writer
    - Xceed Software

    In three words I can sum up everything I've learned about life: it goes on.
  •  03-11-2009, 11:33 AM Post no. 19208 in reply to 19196

    Re: Master/Detail Row expanded

    I had already implemented a DataGridDetailDescription.  It is working in the sense that I can expand any parent row and the child objects are displayed in child rows in a subgrid.  See the code below: (modified slightly to rename the names of my variables)

      class ParentDetail : DataGridDetailDescription
     {
      public ParentDetail()
      {
       this.RelationName = "ParentDetail";
      }

      protected override IEnumerable GetDetailsForParentItem(DataGridCollectionViewBase parentCollectionView, object parentItem)
      {
       
       ParentDataObjectType parentDataObject = parentItem as ParentDataObjectType;

       //If no parent object was given, return an empty list of ChildObjects
       if (parentDataObject == null)
        return new List<ChildObjectType>();
       else
        return parentDataObject.ObservableCollectionChildObjects;
      }
     }

    I'm a bit confused by your answer.  I have looked for other methods that I could override because the GetDetailsForParentItem() method that I'm overriding does not do what I need it to do.  The GetDetailsForParentItem() method is used by the grid when a Parent object is expanded, and the child detail objects are required in order to populate the subgrid (detailconfiguration or whatever the appropriate name is).

    What I need, is when I want create a new child row/object using the InsertRow in the subgrid, two events fire in that process (InitializingNewItem and CreatingNewItem) in creating a new object.  In my code that handles these events, I need access to the parent object so that I can link the new child object to the parent object.  Since the code above is for determining the child detail based on a given parent, it is not useful to me because I don't know which parent object is expanded and had the subgrid's Insert Row used.  I need a reference to that Parent object.

    Also, I have considered using the DataGridControl.CurrentItem, DataGridControl.SelectedItem, and also DataGridControl.GlobalSelectedItem.  However, these are all insufficient because the parent row (or a parent's child row for that matter) could be the selected row that is not the parent row that I am attempting to create a new child record/object for.

    In conclusion, I need a reference to the parent object when creating a child object in the InsertRow of the parent's subgrid.  Is there an API call that I can use, or an override that I can implement to provide that kind of access?

    Thanks...

     

  •  03-12-2009, 12:40 AM Post no. 19220 in reply to 12262

    Re: Master/Detail Row expanded

    Private Sub setGridwidth(ByVal dgrd As GridControl, ByVal intWidthArray() As Integer) For i As Integer = 0 To intWidthArray.Length - 1 dgrd.Columns(1).Width = intWidthArray(i) Next End Sub call it in the where u have given relation for master/detail
  •  03-12-2009, 12:57 AM Post no. 19221 in reply to 12262

    Re: Master/Detail Row expanded

    In xceedgrid how can we expand the width of master and detail columns using vb.net .Please post the code
  •  03-12-2009, 9:06 AM Post no. 19234 in reply to 19208

    Re: Master/Detail Row expanded

    Hi Ryan,

    I had a developer take a look at your question and he believes that it is currently not possible to do what you want. The DataGridCollectionView[Source] does not expose, nor does it allow, the parent item to be retrieved when inserting new items. The DetailDescription is accessible through the event args, but not the parent item.

    As a possible workaround, you could handle the InsertionRow's BeginningEdit event, retrieve it's DataGridContext, which exposes the parent item. 

    I will create a ticket for this issue and have one of the developers take a look to see if it is possible to expose the parent item. 


    Senior Technical Writer
    - Xceed Software

    In three words I can sum up everything I've learned about life: it goes on.
  •  03-12-2009, 5:24 PM Post no. 19255 in reply to 19234

    Re: Master/Detail Row expanded

    Thanks for your reply.

    Your workaround gave me an idea that is currently working.  It seemed to me that a new "DataGridDetailDescription" is created for each parent row, as opposed to using this object in a static way (no static methods).  So, I created my own workaround by changing my implementation of the DataGridDescription class from what I showed in post #19208.  I basically included one extra property, and set that property when the GetDetailsForParentItem() method is called.

     

     class ParentDetail : DataGridDetailDescription
     {
      public ParentDetail()
      {
       this.RelationName = "ParentDetail";
      }

      protected override IEnumerable GetDetailsForParentItem(DataGridCollectionViewBase parentCollectionView, object parentItem)
      {
       
       ParentDataObjectType parentDataObject = parentItem as ParentDataObjectType;

       //If no parent object was given, return an empty list of ChildObjects
       if (parentDataObject == null)
        return new List<ChildObjectType>();
       else
       {
        this.ParentDataObject = parentDataObject;
        return parentDataObject.ObservableCollectionChildObjects;
       }
      }

      internal ParentDataObjectType ParentDataObject { get; set; }
     }

     

    When the DataGrid's CreatingNewItem event is handled, I check the e.CollectionView.ItemType.Name property to see if this string matches the object name of my child object.  Fortunately I'm not using ADO.NET here, or I would be staring at something like "System.Data.DataRow".  At that point I cast the event args e.CollectionView.ParentDetailDescription to type ParentDetail with the following code:

    ParentDetail parentDetail = e.CollectionView.ParentDetailDescription as ParentDetail;

    Now I have access to the parent object via the ParentDataObject property on the parentDetail object!

    I can do a similar thing in the InitializingNewItem event, only this time the workaround is a little bit easier.  Instead of checking the e.CollectiovView.ItemType.Name property, you can check e.Item directly to see if it is the type that you want to deal with (Parent type, Child type, grandchild type, ect for however many Master/Detail nestings you are doing), and still use the same casting techique to the ParentDetail type.

    Hope this helps all other developers consuming the Xceed WPF Grid until the DataGridCreatingNewItemEventArgs and DataGridItemEventArgs are improved to allow direct access to the parent type.

    Thanks Jenny, for the inspiration behind this workaround...

    Filed under:
  •  07-22-2009, 12:40 PM Post no. 22810 in reply to 19255

    Re: Master/Detail Row expanded

    Assuming the parent of ParentDetail will always be ParentDataObjectType, the following class is much simpler making use of the base class version of GetDetailsForParentItem for the standard functionality. Also, no need for the constructor if you specify the RelationName in the XAML code.

    class ParentDetail : DataGridDetailDescription
    {
        protected override IEnumerable GetDetailsForParentItem(DataGridCollectionViewBase parentCollectionView, object parentItem)
        {

            _parentDataObject = (ParentDataObjectType)parentItem;
            return base.GetDetailsForParentItem(parentCollectionView, parentItem);
        }

        private ParentDataObjectType _parentDataObject = null;
        public ParentDataObjectType ParentDataObject
        {
            get
            {
                return _parentDataObject;
            }
        }
    }


    Hope this clarifies things better for anyone who took as long to figure out the above as I did.


    Associate, .NET Development
    Morgan Stanley, UK
  •  03-18-2010, 3:39 PM Post no. 26194 in reply to 22810

    Confused [8-)] Re: Master/Detail Row expanded

    I have found a major flaw with this method that Ryan and I are using.  Because GetDetailsForParentItem is always called whenever detail rows are expanded for the same instance of the DataGridDetailDescription (or PropertyDetailDescription) object, when I access ParentDataObject through DataGridCommittingNewItemEventArgs.CollectionView later in a DataGridCollectionViewSource.CommittingNewItem event handler, it always contains the parent item of the last details rows I expanded, not the one I may be adding a new item for (via the detail insertion row).

    Jenny, you mentioned that a ticket would be raised for this.  Has this been implemented yet?

    Thanks,

    Jason


    Associate, .NET Development
    Morgan Stanley, UK
View as RSS news feed in XML
Contact | Site Map | Reviews | Legal Terms of Use | Trademarks | Privacy Statement Copyright 2011 Xceed Software Inc.