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.
Unfortunately, activation email could not send to your email. Please try again.

Group a numeric column based on defined value rages

Thread ID:

Created:

Updated:

Platform:

Replies:

31176 Jun 30,2005 05:09 PM Jul 5,2005 08:55 AM Windows Forms 6
loading
Tags: GridControl
Lan Mo
Asked On June 30, 2005 05:09 PM

Hello, I want to add a classifcation function to GGC. When i right click on a column header, it will display a form to let user define several value ranges for the numeric column, then it will add the column to group based on the defined column value ranges. How can I group a numeric column based on defined value rages? any samples? Lan

Administrator [Syncfusion]
Replied On June 30, 2005 05:38 PM

Here is a kb link discussing this. http://64.78.18.34/Support/article.aspx?id=10507

Lan Mo
Replied On July 3, 2005 04:44 PM

Hello, This sample is what I want. I didn''t see where is the code to group col2 to five ranges: 1: " < 10"; 2: "10 - 19"; 3: "20 - 29"; 4: "30 - 39"; 5: " >= 40"; For example, if I want to group col2 by three ranges: "Col2<20", "20<=col2<35" and "35<=col2" How and where I add the code in? Thanks, >Here is a kb link discussing this. > >http://64.78.18.34/Support/article.aspx?id=10507

Administrator [Syncfusion]
Replied On July 3, 2005 07:01 PM

You would change two methods.
private void gridGroupingControl1_QueryCellStyleInfo(object sender, Syncfusion.Windows.Forms.Grid.Grouping.GridTableCellStyleInfoEventArgs e)
{
	if (e.TableCellIdentity.GroupedColumn != null && e.TableCellIdentity.DisplayElement.ParentGroup != null
		&& e.TableCellIdentity.DisplayElement.ParentGroup.Category is int
		)
	{
		if (e.TableCellIdentity.DisplayElement is CaptionRow
			&& e.TableCellIdentity.GroupedColumn.Name == "Col2")
		{
			int cat = (int) e.TableCellIdentity.DisplayElement.ParentGroup.Category;
			string ret = "";
			switch (cat)
			{
				case 1:     
					ret = " < 20";
					break;
				case 2:     
					ret = "20 - 35";
					break;
				case 3:     
					ret = "> 35";
					break;
			}
			e.Style.CellValue = String.Format("{0}: {1} Items.", ret, e.TableCellIdentity.DisplayElement.ParentGroup.GetChildCount());
		}
	}
}


public static int GetCategory(int i)
{
	int ret = 0;
	if(i < 20)
		ret = 1;
	else if(i >= 20 && i < 35)
		ret = 2;
	else  
		ret = 3;
	return ret;
}

Lan Mo
Replied On July 4, 2005 02:18 PM

Hello, Your code works fine for "int" type column "col2". How can I make it also work for "datatime" type and "double" type columns? Thanks, >You would change two methods. > >
>private void gridGroupingControl1_QueryCellStyleInfo(object sender, Syncfusion.Windows.Forms.Grid.Grouping.GridTableCellStyleInfoEventArgs e)
>{
>	if (e.TableCellIdentity.GroupedColumn != null && e.TableCellIdentity.DisplayElement.ParentGroup != null
>		&& e.TableCellIdentity.DisplayElement.ParentGroup.Category is int
>		)
>	{
>		if (e.TableCellIdentity.DisplayElement is CaptionRow
>			&& e.TableCellIdentity.GroupedColumn.Name == "Col2")
>		{
>			int cat = (int) e.TableCellIdentity.DisplayElement.ParentGroup.Category;
>			string ret = "";
>			switch (cat)
>			{
>				case 1:     
>					ret = " < 20";
>					break;
>				case 2:     
>					ret = "20 - 35";
>					break;
>				case 3:     
>					ret = "> 35";
>					break;
>			}
>			e.Style.CellValue = String.Format("{0}: {1} Items.", ret, e.TableCellIdentity.DisplayElement.ParentGroup.GetChildCount());
>		}
>	}
>}
>
>
>public static int GetCategory(int i)
>{
>	int ret = 0;
>	if(i < 20)
>		ret = 1;
>	else if(i >= 20 && i < 35)
>		ret = 2;
>	else  
>		ret = 3;
>	return ret;
>}
>

Administrator [Syncfusion]
Replied On July 4, 2005 03:01 PM

Here is a sample where Col2 is a DataTime and the code groups the dates by Months. http://www.syncfusion.com/Support/user/uploads/CustomizedGrouping_351ad4f.zip You modify the GetCategory method to accept the type of your object (double or DateTime), and return a value to indicate the group the passed in value belongs to.

Lan Mo
Replied On July 5, 2005 08:55 AM

Hello Clay, Thank you for your excellent support. Now my "grouping by range" function works well. I would like say your support is the best I''ve ever had. Lan >Here is a sample where Col2 is a DataTime and the code groups the dates by Months. >http://www.syncfusion.com/Support/user/uploads/CustomizedGrouping_351ad4f.zip > >You modify the GetCategory method to accept the type of your object (double or DateTime), and return a value to indicate the group the passed in value belongs to. > >

CONFIRMATION

This post will be permanently deleted. Are you sure you want to continue?

Sorry, An error occured while processing your request. Please try again later.

You are using an outdated version of Internet Explorer that may not display all features of this and other websites. Upgrade to Internet Explorer 8 or newer for a better experience.

;