ColumnGroupDescriptor question

9 posts, 1 answers
  1. doc21
    doc21 avatar
    3 posts
    Member since:
    Mar 2011

    Posted 24 Mar 2011 Link to this post

    Hi,

    This is what I am doing. I create a datatable using (look at http://blogs.telerik.com/vladimirenchev/posts/09-04-23/lightweight_datatable_for_your_silverlight_applications.aspx)  and I set the item source to the  grid which works fine. The reason using datatable being the columns that I want to display are never same and keep changing.

    Now I want to add a ColumnGroupDescriptor. This is what I did

    DataTable dataTable =new DataTable();
    Code that fills the data
     
    this.myGrid.ItemSource=dataTable;
     
    ColumnGroupDescriptor descriptor = new ColumnGroupDescriptor();
    descriptor.Column = this.myGrid.Columns[0];
    this.myGrid.GroupDescriptors.Add(descriptor);

    However my problem is at the code fails at "this.myGrid.Columns[0]" and says "Index was out of range. " which tells me the grid has not be completly
    loaded because when I debug it says column count is 0 eventhough the itemsource is set to a datatable that
    has 3 columns.

    So I try to put the ColumnGroupDescriptor code in DataLoaded event of the grid.
    But the error I get now is
    "Cannot change ObservableCollection during a CollectionChanged or PropertyChanged event."

    Can anyone please help me out.

    Thanks


  2. Answer
    Yavor Georgiev
    Admin
    Yavor Georgiev avatar
    982 posts

    Posted 24 Mar 2011 Link to this post

    Hello doc21,

     The DataLoaded event fires after grouping as well, so you need to remove the event handler the first time it fires.

    All the best,
    Yavor Georgiev
    the Telerik team
  3. doc21
    doc21 avatar
    3 posts
    Member since:
    Mar 2011

    Posted 24 Mar 2011 Link to this post

    Thanks, it solved my problem
  4. Jack
    Jack avatar
    14 posts
    Member since:
    Sep 2011

    Posted 24 Nov 2011 Link to this post

    Hi, I'm having the same problem, what do you mean by removing the event handler the first time it fires??

    If I remove it the event handler, where would I put my columngroupdescriptor code?

    Thanks
  5. Maya
    Admin
    Maya avatar
    4062 posts

    Posted 25 Nov 2011 Link to this post

    Hi Jack,

    The idea was to unsubscribe from the DataLoaded event once it is fired:

    public MainPage()
            {
                InitializeComponent();
                this.clubsGrid.DataLoaded += new EventHandler<EventArgs>(clubsGrid_DataLoaded);
            }
     
            void clubsGrid_DataLoaded(object sender, EventArgs e)
            {
                this.clubsGrid.DataLoaded -= new EventHandler<EventArgs>(clubsGrid_DataLoaded);
                //Implement your logic here.
            }

    I hope it helps. 

    Kind regards,
    Maya
    the Telerik team

    Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get it now >>

  6. Jack
    Jack avatar
    14 posts
    Member since:
    Sep 2011

    Posted 25 Nov 2011 Link to this post

    Hi,

    Thank you so much, that was exactly what I was looking for.

    Thanks!!!!
  7. Valery
    Valery avatar
    7 posts
    Member since:
    Jan 2013

    Posted 19 Feb 2013 Link to this post

    And why does DataLoaded event fire after changing the GroupDescriptors?  why not KeyPressed or MouseClicked? When data is really loaded, there is DataLoading, then DataLoaded, and when GroupDescriptors, FilterDescriptors or SortDescriptors are changed, there is only DataLoaded. That's weird and inconsistent.
  8. Vlad
    Admin
    Vlad avatar
    11100 posts

    Posted 19 Feb 2013 Link to this post

    Hi,

     DataLoaded event is raised every time you perform data-shaping operation like sorting, grouping, filtering, paging, etc. KeyPressed or MouseClicked are not something related to data.

    Regards,
    Vlad
    the Telerik team

    Explore the entire Telerik portfolio by downloading Telerik DevCraft Ultimate.

  9. Valery
    Valery avatar
    7 posts
    Member since:
    Jan 2013

    Posted 19 Feb 2013 Link to this post

    from the event's name DataLoaded I would assume that it happens whenever data is loaded, not "shaped". If you declare as a feature that this event is also raised on changing filter, sort and group descriptors, this has to be explicitly documented and ideally backed by your reasons to do so. As well as the fact that DataLoadING event happens only on true data load operations (followed by DataLoaded). And MouseClicked and KeyPressed are definitely related to data because the user types or clicks to change filtering or sorting. What I'm saying is raising DataLoaded event on changing filters isn't obvious and I would call it a bug unless it's documented behavior.
Back to Top