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

Adding column group dynamically using C#

Thread ID:

Created:

Updated:

Platform:

Replies:

133015 Oct 4,2017 06:43 AM UTC Oct 5,2017 10:00 PM UTC Xamarin.Forms 1
loading
Tags: SfDataGrid
Barak Rozenfeld
Asked On October 4, 2017 06:43 AM UTC

Hi love you data grid.

I want to know
is it possible to create a data grid column group manually(dynamically) using C# and not Xaml?

I want to create a datagrid which contain a some rows within group and some of the rows without a group

would appreciate code example

thanks

Ashok N [Syncfusion]
Replied On October 5, 2017 10:00 PM UTC

Hi Barak, 
 
Thanks for contacting Syncfusion support. 
 
Query regarding Groping from c# code: 
 
You perform grouping from the code by defining the GroupColumnDescription object and adding it in the SfDataGrid.GroupColumnDescriptions collection. Please refer the below UG link for more details: 
 
 
Query regarding some rows within group and some of the rows without a group:

You can achieve your requirement by using separate API and handling QueryRowHeight event. Group will be created based on value of the group property and you can hide the Group header by setting QueryRowHeightEventArgs.Height is 0. In our example we have hide the Group for zzexcludedGroup Group key, so in view those  item will be displayed without grouping.
 

Refer below code Example: 
 
// property declaration in Model 
 
string _groupProperty = "zzexcludedGroup"; 
public string GroupProperty 
{ 
    get 
    { 
        return _groupProperty; 
    } 
    set 
    { 
        this._groupProperty = value; 
        RaisePropertyChanged("GroupProperty"); 
    } 
}  
 
// Value set in OrderInfoRepository class 
if (i <= 10030) 
    ord.GroupProperty = ord.CustomerID; 
orderDetails.Add(ord);  
 
// Event handling  
 
private void DataGrid_QueryRowHeight(object sender, QueryRowHeightEventArgs e) 
{ 
    if(dataGrid.IsCaptionSummaryRow(e.RowIndex)) 
    { 
        var captionRow = dataGrid.GetRowGenerator().Items.FirstOrDefault(rw => rw.RowIndex == e.RowIndex); 
        if(captionRow != null) 
        { 
            var group = captionRow.RowData as Group; 
            if (group != null && group.Key.ToString() == "zzexcludedGroup") 
            { 
                e.Height = 0; 
                e.Handled = true; 
            } 
        } 
    } 
}  
   

Regards,
Ashok      
 


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.

Warning Icon 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.Close Icon

;