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. (Last updated on: November 16, 2018).
Unfortunately, activation email could not send to your email. Please try again.
Syncfusion Feedback

some quesion about ggc

Thread ID:

Created:

Updated:

Platform:

Replies:

125404 Aug 15,2016 06:52 AM UTC Aug 19,2016 04:47 AM UTC WinForms 5
loading
Tags: GridGroupingControl
ligyste
Asked On August 15, 2016 06:52 AM UTC

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!


Mohanraj Gunasekaran [Syncfusion]
Replied On 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. 
 


ligyste
Replied On 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.

Mohanraj Gunasekaran [Syncfusion]
Replied On 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. 
 


ligyste
Replied On August 18, 2016 09:12 AM UTC

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

Mohanraj Gunasekaran [Syncfusion]
Replied On 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. 


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.

Please sign in to access our forum

or the page will be automatically redirected to sign-in page in 10 seconds.

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

;