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

some quesion about ggc

1、When I add a new group to the droparea,I want to sort all the groups' caption by the group's record count ,can anyone give me a sample? 
https://www.syncfusion.com/forums/42569/grouping-engine-sort-by-group-count
It's sample is too old....
2、I bind a datatable to a ggc,when the ggc without any group,I select a row.how to get the row's all part ,
for expmple,every column's value,name,and the index of in the orginal  datatable?

thanks!


5 Replies

MG Mohanraj Gunasekaran Syncfusion Team August 16, 2016 04:52 PM UTC

Hi Ligyste, 

Thanks for using Syncfusion product, 


When I add a new group to the droparea,I want to sort all the groups' caption by the group's record count ,can anyone give me a sample?  
In order to sort the groups based on the record count, you can use the CustomGroupComparer which is derived from IGroupSortOrderComparer. Please refer the below code snippet and attached sample. 

Code snippet: 
sortColumn.GroupSortOrderComparer = new CustomGroupComparer(); 
public class CustomGroupComparer : IGroupSortOrderComparer 
{ 
    public int Compare(object x, object y) 
    { 
        Syncfusion.Grouping.Group gx = (Syncfusion.Grouping.Group)x; 
        Syncfusion.Grouping.Group gy = (Syncfusion.Grouping.Group)y; 
 
        int gxRecordCount = gx.GetRecordCount(); 
        int gyRecordCount = gy.GetRecordCount(); 
 
        return gyRecordCount - gxRecordCount; 
    } 
 
    /// <summary>For internal use. 
    /// Get the dependantFields. 
    /// </summary> 
    /// <param name="td">The table descriptor.</param> 
    /// <returns>Returns the array of descriptor names.</returns> 
    public string[] GetDependantFields(TableDescriptor td) 
    { 
        return new string[] { }; 
    }  
} 
I bind a datatable to a ggc,when the ggc without any group,I select a row.how to get the row's all part , 
for expmple,every column's value,name,and the index of in the orginal  datatable? 

The reported scenario can be achieved by handling the CellClick event. Please refer the below code snippet and attached sample 

Code snippet: 
void gridGroupingControl1_TableControlCellClick(object sender, GridTableControlCellClickEventArgs e) 
{ 
    GridTableCellStyleInfo style = this.gridGroupingControl1.TableControl.GetTableViewStyleInfo(e.Inner.RowIndex, e.Inner.ColIndex); 
             
    //Record value 
    Record record = style.TableCellIdentity.DisplayElement.GetRecord(); 
 
    //Column value 
    String value = record.GetValue("Id").ToString(); 
 
    //Column name 
    String columnName=style.TableCellIdentity.Column.Name; 
 
    //Record index 
    int index = style.TableCellIdentity.DisplayElement.GetRowIndex(); 
    GridTableCellStyleInfoIdentity id = style.TableCellIdentity; 
    if (id.DisplayElement.Kind == DisplayElementKind.Record) 
    { 
        Record rec = id.DisplayElement.GetRecord(); 
        int actualIndex = rec.Id;//Real RowIndex 
    } 
 
} 


Sample link: Sort all the Groups 
 
 
Regards, 
Mohanraj G. 
 



LI ligyste August 17, 2016 12:00 AM UTC

Thanks,question 2,I want a sample way to get the record's column name and value when I don't know  the the column name.Thank for your help,Now ,I can use the orginal rowindex in the datatable to achieve this.


MG Mohanraj Gunasekaran Syncfusion Team August 17, 2016 08:47 AM UTC

Hi Ligyste, 

Thanks for your update, 

In order to get the column name and cell values without using column name, you can use the Record.GetData() method. This method provides the row object of the underlying datasource. Please refer the below code snippet and attached sample, 

Code snippet 

GridTableCellStyleInfo style = this.gridGroupingControl1.TableControl.GetTableViewStyleInfo(e.Inner.RowIndex, e.Inner.ColIndex); 
 
//Record value 
Record record = style.TableCellIdentity.DisplayElement.GetRecord(); 
 
String cellvalue = style.CellValue.ToString(); 
 
DataRowView rowView=(record.GetData() as DataRowView); 
string colName = string.Empty; 
string cellvalues = string.Empty; 
if (rowView != null) 
{ 
 
//Column name 
int colcount = rowView.Row.Table.Columns.Count; 
for (int j = 0; j < colcount; j++) 
{ 
    colName = colName + rowView.Row.Table.Columns[j].ColumnName+"\n\t"; 
                     
                     
} 
MessageBox.Show("Current record column names:\n\t" + colName); 
 
//  Values.Add(rowView.Row.ItemArray.GetValue(i).ToString()); 
foreach (object data in rowView.Row.ItemArray) 
{ 
    cellvalues = cellvalues + data.ToString() + "\n\t"; 
} 
 
 
MessageBox.Show("Current record cell values:\n\t" + cellvalues); 
 
// get the Specfic value using column index 
string specifcvalue = rowView.Row[2].ToString(); 
 
 
Sample link: DataGrid 
 
Regards, 
Mohanraj G. 
 



LI ligyste August 18, 2016 09:12 AM UTC

Thank you very much!.This is a very useful method.


MG Mohanraj Gunasekaran Syncfusion Team August 19, 2016 04:47 AM UTC

Hi Ligyste, 

Thanks for your update, 

We are glad to know that provided solution useful to you. Please let us know if you need any further assistance.  
Regards, 
Mohanrj G. 


Loader.
Up arrow icon