Group a numeric column based on defined value rages

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

6 Replies

AD Administrator Syncfusion Team June 30, 2005 09:38 PM UTC

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


LM Lan Mo July 3, 2005 08:44 PM UTC

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


AD Administrator Syncfusion Team July 3, 2005 11:01 PM UTC

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;
}


LM Lan Mo July 4, 2005 06:18 PM UTC

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;
>}
>


AD Administrator Syncfusion Team July 4, 2005 07:01 PM UTC

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.


LM Lan Mo July 5, 2005 12:55 PM UTC

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. > >

Loader.
Up arrow icon