We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. Image for the cookie policy date

Expand group(s) from ListChanged event

Hello, I''ve been struggling with creating an algorithm for the following problem for a few hours now, I hope you can help. It appears to be simple. I am listening to the ListChanged event of the DataView providing the data for my GridGrouping control linkMonitorGrid, and if the [Status] field has a certain condition (values 0 or 1), I want to expand the group in which that child resides. At first I thought about using the NewIndex property and passing this to my own method, CheckForPossibleGridExpands: private void OnLinkViewChanged ( object sender, ListChangedEventArgs e ) { // if it''s an addition or an update if ( e.ListChangedType == ListChangedType.ItemAdded || e.ListChangedType == ListChangedType.ItemChanged ) { CheckForPossibleGridExpands( e.NewIndex ); } else if ( e.ListChangedType == ListChangedType.Reset ) { CheckForPossibleGridExpands(); } } private void CheckForPossibleGridExpands(int rowIndex) { int status = Convert.ToInt16(this.linkMonitorGridView.Table.Rows[rowIndex]["Status"]); // compare the new status with the one currently stored in the grid if ( status == 0 || status == 1 ) { // fetch the primary key MarketID string marketId = this.linkMonitorGridView.Table.Rows[rowIndex]["MarketID"]; Syncfusion.Grouping.Table table = this.linkMonitorGrid.TableModel.Table; Syncfusion.Grouping.ElementsInTableCollection elements = table.Elements; //table.FilteredRecords RecordFilterDescriptor rfd = new RecordFilterDescriptor("MarketID", new Syncfusion.Grouping.FilterCondition(FilterCompareOperator.Equals, marketId) ); RecordFilterDescriptorCollection rfdc = new RecordFilterDescriptorCollection(); rfdc.Add(rfd); // expand the grid group table.ExpandAllGroups(); } } and overloading this method with one which iterates through the linkMonitorGridView.Table.Rows when I recieve a ListChangedType.Reset, but i am not thinking that I should perhaps apply a filter to the this.linkMonitorGrid.TableModel.Table? Is that the right approach?? Also am I correct that linkMonitorGrid.TableModel.Table.ExpandAllGroups() will expand the group one I have located the record in the table, or do I need to be traversing some actual grid properties to correctly use ExpandAllGroups()??? Thanks in advance for your assistance. Jason Southgate.

3 Replies

AD Administrator Syncfusion Team October 21, 2004 07:04 AM UTC

Hi Jason, applying a filter is not a good approach. It will modify the collection of available records for the table (Table.FilteredRecords). But you can use the UnsortedRecords collection and look up a record based on its source index. See below. private void OnLinkViewChanged ( object sender, ListChangedEventArgs e ) { // if it''''s an addition or an update if ( e.ListChangedType == ListChangedType.ItemAdded || e.ListChangedType == ListChangedType.ItemChanged ) { Record r = this.linkMonitorGrid.Table.UnsortedRecords[e.NewIndex]; // and then either r.ParentTable.ShowRecord(r, true); // or r.ParentGroup.IsExpanded = true; } else if ( e.ListChangedType == ListChangedType.Reset ) { this.linkMonitorGrid.Table.ExpandAllGroups(); } } FYI - In the next version there will also be a PrimaryKeySortedRecords collection that you can then also use to quickly look up a record based on a primary key, e.g. Record r = this.linkMonitorGrid.Table.PrimaryKeySortedRecords[primaryKeyValue]; Stefan


JS Jason Southgate October 21, 2004 07:56 AM UTC

Perfect Stefan, I did this, in the end and overloaded the method too to cover ListChangedType.Reset: private void OnLinkViewChanged ( object sender, ListChangedEventArgs e ) { // refresh the grid summaries this.linkMonitorGrid.Table.SummariesDirty = true; this.linkMonitorGrid.Refresh(); // if it''s an addition or an update if ( e.ListChangedType == ListChangedType.ItemAdded || e.ListChangedType == ListChangedType.ItemChanged ) { CheckForPossibleGridExpands( e.NewIndex ); } else if ( e.ListChangedType == ListChangedType.Reset ) { CheckForPossibleGridExpands(); } } private void CheckForPossibleGridExpands( int rowIndex ) { int status = Convert.ToInt16( this.linkMonitorGridView.Table.Rows[rowIndex]["Status"] ); // compare the new status with the one currently stored in the grid if ( status == 0 || status == 1 ) { Record r = this.linkMonitorGrid.Table.UnsortedRecords[rowIndex]; // expand the grid group r.ParentGroup.IsExpanded = true; } } private void CheckForPossibleGridExpands() { for ( int i=0; i

JS Jason Southgate October 21, 2004 07:58 AM UTC

Sorry this was the overloaded method in the end: private void CheckForPossibleGridExpands() { for ( int i=0; i
Loader.
Live Chat Icon For mobile
Up arrow icon