This is a migrated thread and some comments may be shown as answers.

change GroupByExpression Programmatically

3 Answers 248 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Mojtaba
Top achievements
Rank 1
Mojtaba asked on 25 Feb 2009, 11:14 AM
I am trying too change group by expression Programmatically like this code:
grdHistory.MasterGridViewTemplate.GroupByExpressions.Clear(); 
GridGroupByExpression expression1 = GridGroupByExpression.Parse("[SmsTitle] as [SmsTitle] format '{1} ', count([Serial]) as [Template] format '({1} {0})' Group By [SmsTitle]"); 
grdHistory.MasterGridViewTemplate.GroupByExpressions.Add(expression1); 
grdHistory.DataSource = SMSPanelComponent.GetSmsTemplates(); 
but after that grid is bound in normal mode without any group i.e(groupcount=0).
I test my group expression in design mode and it worked correctly.
any idea??

3 Answers, 1 is accepted

Sort by
0
Jack
Telerik team
answered on 26 Feb 2009, 09:30 AM
Hi Mojtaba,

You are changing the DataSource after adding the new group expression. When the new data source does not contain all the columns from the group expression, it will be removed.

If this is not the case, please open a support ticket and send me the source of your application. This way I will be able to investigate the case in detail and locate the issue.

If you have any other questions, do not hesitate to write us.
 
Best wishes,
Jack
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Check out the tips for optimizing your support resource searches.
0
Mojtaba
Top achievements
Rank 1
answered on 28 Feb 2009, 07:26 AM
Hi Jack,

Thank you for your reply. I correct this problem but I can't understand how??!! so I write my scenario for you, be patient.....
I have a gridview that supports 2 status:
1- Show in queue SMS (grouped by date).
2- Show SMS templates (grouped by SMSTitle)
I supposed first status in design mode, and add my custom column in design mode, and then remove auto generated column after binding completed.(because if I set autogenerate=false then grouping dose not work??!!)
and for second status I write this code in page load.
 
//form constructor 
public MainForm() 
InitializeComponent(); 
switch (PageMode) 
    case Modes.InQeueSms: 
        grdHistory.DataSource = SMSPanelComponent.GetSentSms(); 
        break
    case Modes.ShowTemplates:
        //Correct custom column
        grdHistory.MasterGridViewTemplate.Columns[1].FieldName = "Title"
        grdHistory.MasterGridViewTemplate.GroupByExpressions.Clear(); 
        GridGroupByExpression expression1 = GridGroupByExpression.Parse("[SmsTitle] as [SmsTitle] format '{1} ', count([Serial]) as [Template] format '({1} {0})' Group By [SmsTitle]"); 
        grdHistory.MasterGridViewTemplate.GroupByExpressions.Add(expression1); 
       grdHistory.DataSource = SMSPanelComponent.GetSmsTemplates(); 
       break
 
and then grouping does not work. I changed 2 line like this and grouping worked.
//form constructor  
public MainForm()  
{  
InitializeComponent();  
switch (PageMode)  
{  
    case Modes.InQeueSms:  
        grdHistory.DataSource = SMSPanelComponent.GetSentSms();  
        break;  
    case Modes.ShowTemplates: 
        //Correct custom column 
        //Comment this line grdHistory.MasterGridViewTemplate.Columns[1].FieldName = "Title"; 
        //Add this line 
        grdHistory.Columns.Clear();  
        grdHistory.MasterGridViewTemplate.GroupByExpressions.Clear();  
        GridGroupByExpression expression1 = GridGroupByExpression.Parse("[SmsTitle] as [SmsTitle] format '{1} ', count([Serial]) as [Template] format '({1} {0})' Group By [SmsTitle]");  
        grdHistory.MasterGridViewTemplate.GroupByExpressions.Add(expression1);  
       grdHistory.DataSource = SMSPanelComponent.GetSmsTemplates();  
       break;  
}  
}  
 
In fact I remove my custom column, and it worked, but I can't understand why??!!
0
Jack
Telerik team
answered on 03 Mar 2009, 11:18 AM
Hello Mojtaba,

I am glad to hear that you have found solution for this issue.

The FieldName property is used to associate a column with the corresponding data field in the data table. The grouping uses the same FiledName value. Because of this, you will observe this effect when you change the value for a grouped column.

I you have any further questions, please write us back.

All the best,
Jack
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Check out the tips for optimizing your support resource searches.
Tags
GridView
Asked by
Mojtaba
Top achievements
Rank 1
Answers by
Jack
Telerik team
Mojtaba
Top achievements
Rank 1
Share this question
or