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

Programming Grouping

I want to group a column by code and make it not visible in the coulmns when a column is added to group, re-visible when user drag it back. To add it to group, I use code: GGC1.TableDescriptor.GroupedColumns.Clear(); GGC1.TableDescriptor.GroupedColumns.Add("year"); To hide it, GGC1.TableDescriptor.VisibleColumns.Remov("year"); To re-visible it, GGC1.TableDescriptor.VisibleColumns.Add("year"); But I don''t know in which enents I should put hide/re-show codes in. and How can I dynamiclly know the column name instead of hard-coded "year" when user drag/drop a column in the "grouping drop area" Thanks, Lan

9 Replies

AD Administrator Syncfusion Team June 2, 2005 03:18 PM UTC

To hide the grouped column, you can subcribe to the grid.TableDescriptor.GroupedColumns.Changing event to show and hide the column in your event handler.
private void GroupedColumns_Changing(object sender, Syncfusion.Collections.ListPropertyChangedEventArgs e)
{
	SortColumnDescriptor scd = e.Item as SortColumnDescriptor;
	if(e.Action == Syncfusion.Collections.ListPropertyChangedType.Remove)
			this.gridGroupingControl1.TableDescriptor.VisibleColumns.Add(scd.Name);
	else if(e.Action == Syncfusion.Collections.ListPropertyChangedType.Add)
	this.gridGroupingControl1.TableDescriptor.VisibleColumns.Remove(scd.Name);
}


LM Lan Mo June 2, 2005 03:39 PM UTC

I can''t find the event grid.TableDescriptor.GroupedColumns.Changing in Grid property window (event tab) lan >To hide the grouped column, you can subcribe to the grid.TableDescriptor.GroupedColumns.Changing event to show and hide the column in your event handler. > >
>private void GroupedColumns_Changing(object sender, Syncfusion.Collections.ListPropertyChangedEventArgs e)
>{
>	SortColumnDescriptor scd = e.Item as SortColumnDescriptor;
>	if(e.Action == Syncfusion.Collections.ListPropertyChangedType.Remove)
>			this.gridGroupingControl1.TableDescriptor.VisibleColumns.Add(scd.Name);
>	else if(e.Action == Syncfusion.Collections.ListPropertyChangedType.Add)
>	this.gridGroupingControl1.TableDescriptor.VisibleColumns.Remove(scd.Name);
>}
>
>


LM Lan Mo June 2, 2005 03:54 PM UTC

I added the event, but it never fired when add/remove groups this.gridGroupingControl1.TableDescriptor.GroupedColumns.Changing+=new Syncfusion.Collections.ListPropertyChangedEventHandler(GroupedColumns_Changing); Why? Lan >To hide the grouped column, you can subcribe to the grid.TableDescriptor.GroupedColumns.Changing event to show and hide the column in your event handler. > >
>private void GroupedColumns_Changing(object sender, Syncfusion.Collections.ListPropertyChangedEventArgs e)
>{
>	SortColumnDescriptor scd = e.Item as SortColumnDescriptor;
>	if(e.Action == Syncfusion.Collections.ListPropertyChangedType.Remove)
>			this.gridGroupingControl1.TableDescriptor.VisibleColumns.Add(scd.Name);
>	else if(e.Action == Syncfusion.Collections.ListPropertyChangedType.Add)
>	this.gridGroupingControl1.TableDescriptor.VisibleColumns.Remove(scd.Name);
>}
>
>


AD Administrator Syncfusion Team June 2, 2005 05:37 PM UTC

Here is a little sample that worked for me using 3.2.1.0. http://www.syncfusion.com/Support/user/uploads/GGC_HideGroups_4beaa152.zip


LM Lan Mo June 3, 2005 03:03 PM UTC

I got your sample. It works well. I also create a new form, add code like your sample, it works well also. But I add the same code to my real form, the event is never fired. I can''t figure out what settings could prevent the event. My GGC form is a generic form to edit any kind table data. Lan >Here is a little sample that worked for me using 3.2.1.0. > >http://www.syncfusion.com/Support/user/uploads/GGC_HideGroups_4beaa152.zip > >


AD Administrator Syncfusion Team June 3, 2005 03:14 PM UTC

Check and make sure the code where you subscribe to this event in your project is hit. Are you using nested tables in your application? The sample only used a flat table and grouped it. If you are trying to do this for nested tables, then you would have to subscribe to the event for each one of nested tables. If you can upload a sample showing the problem, we can try to track it down.


LM Lan Mo June 3, 2005 03:41 PM UTC

I upload my form''s file. I''am afraid you can''t run it because it has to use our definition database tables. lan >Check and make sure the code where you subscribe to this event in your project is hit. > >Are you using nested tables in your application? The sample only used a flat table and grouped it. If you are trying to do this for nested tables, then you would have to subscribe to the event for each one of nested tables. > >If you can upload a sample showing the problem, we can try to track it down. frmGrid_9606.zip frmGrid_7291.zip


AD Administrator Syncfusion Team June 3, 2005 05:05 PM UTC

Try subscribing to the event after you set the datasource: gdBase.DataSource = mGridDataSet.Tables[table]; this.gdBase.TableDescriptor.GroupedColumns.Changing += new Syncfusion.Collections.ListPropertyChangedEventHandler(GroupedColumns_Changing); You will also have to find a good spot to unsubscribe to it as you do not want multiple handlers hooked.


LM Lan Mo June 3, 2005 05:35 PM UTC

You are great!!! I did as you said, It works. whenever I re-load data, I unbound datasource and unsubscribe the event by //unbound grid gdBase.DataSource=null; //unsubscribe the event this.gdBase.TableDescriptor.GroupedColumns.Changing -= new Syncfusion.Collections.ListPropertyChangedEventHandler(GroupedColumns_Changing); After loaded table data, I bound datasource and subscribe the event // bound to grid gdBase.DataSource = mGridDataSet.Tables[table]; //subscribe the event this.gdBase.TableDescriptor.GroupedColumns.Changing += new Syncfusion.Collections.ListPropertyChangedEventHandler(GroupedColumns_Changing); Thanks for great support! Lan Here is copy of new LoadData() code: private void LoadData(string table,string field,string Where,int SubsetID) { try { //unbound grid gdBase.DataSource=null; //unsubscribe the event this.gdBase.TableDescriptor.GroupedColumns.Changing -= new Syncfusion.Collections.ListPropertyChangedEventHandler(GroupedColumns_Changing); gdBase.TableDescriptor.Columns.Clear(); gdBase.ResetTableDescriptor(); // this avoid "No current record error" when lasr record is not existing in the new gris gdBase.Table.ResetCurrentRecord(); gdBase.Table.ResetCurrencyManager(); // retrieve data // if (table.ToUpper()=="SECT_ATTRIBUTE") // for attribute grid tree // mSingleTableObj=new BL.singleTable(table,null,Where,SubsetID); // else // mSingleTableObj=new BL.singleTable(table,field,Where,SubsetID); mSingleTableObj=new BL.singleTable(table,field,Where,SubsetID); mGridDataSet = mSingleTableObj.LoadDataSet(); // bound to grid //DataTable tb=mGridDataSet.Tables[table]; gdBase.DataSource = mGridDataSet.Tables[table]; //subscribe the event this.gdBase.TableDescriptor.GroupedColumns.Changing += new Syncfusion.Collections.ListPropertyChangedEventHandler(GroupedColumns_Changing); gdBase.TableDescriptor.Columns.LoadDefault(); // load table field definitions dsFields=BL.Access.LoadDataSet("dict_field",null,"table_name=''" +table +"''"); // set to the first record so it will be highlighted //gdBase.Table.CurrentRecord = gdBase.Table.Records[0]; } catch (Exception e) { MessageBox.Show(e.Message); } } >Try subscribing to the event after you set the datasource: > >gdBase.DataSource = mGridDataSet.Tables[table]; >this.gdBase.TableDescriptor.GroupedColumns.Changing += new Syncfusion.Collections.ListPropertyChangedEventHandler(GroupedColumns_Changing); > > >You will also have to find a good spot to unsubscribe to it as you do not want multiple handlers hooked.

Loader.
Up arrow icon