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

Custom cell type dynamically based on Cell text

Thread ID:

Created:

Updated:

Platform:

Replies:

129470 Mar 20,2017 05:59 PM UTC Mar 22,2017 09:33 AM UTC Windows Forms 3
loading
Tags: GridGroupingControl
Kevin
Asked On March 20, 2017 06:03 PM UTC

Hi Team,

I need to change the nested table specific cell type as Control based on Cell value. For example, need to set the child table cell type as control if parent record of corresponding child table row value matches some condition. 

The below code set all rows in the specified column as Checkbox. But I need to set the cell type like above.
this.gridGroupingControl1.TableDescriptor.Columns[2].Appearance.AnyRecordFieldCell.CellType = GridCellTypeName.CheckBox

I tried in QueryCellStyleInfo, based on column and row index I have changed the cell style as control. But instead of row and column index, I need to set the cell type based on Parent record value. 
Also, Is there any other way to achieve this? Because QueryCellStyleInfo called every time on cell action. My version is 14.2 and targetting .Net 3.5

Thanks,
Kevin

Piruthiviraj Malaimelraj [Syncfusion]
Replied On March 21, 2017 10:29 AM UTC

Hi Kevin, 
 
Thanks for the update. 
 
We could able to understand your scenario. In order to achieve your scenario, QueryCelllStyleInfo event can be used. In the attached sample, we have set the “CheckBox” celltype for a column of child table , if parent record’s CategoryName(column name) value is “Beverages” .Please make use of the below code, 
 
Code example: 
this.gridGroupingControl1.QueryCellStyleInfo += new GridTableCellStyleInfoEventHandler(gridGroupingControl1_QueryCellStyleInfo); 
 
void gridGroupingControl1_QueryCellStyleInfo(object sender, GridTableCellStyleInfoEventArgs e) 
{ 
    if (e.Style.TableCellIdentity.DisplayElement.Kind == DisplayElementKind.Record) 
    { 
        Record record = e.Style.TableCellIdentity.DisplayElement.GetRecord(); 
         
        //To check the child table records. 
        if (record != null && record.ParentTable.FilteredChildTable != null 
            && record.Kind == DisplayElementKind.Record) 
        { 
            //Gets the parent record. 
            Record parentRecord = record.ParentChildTable.ParentNestedTable.ParentRecord; 
 
            //Set the celltype for child table column based on parent record. 
            if (parentRecord.GetValue("CategoryName").ToString() == "Beverages") 
            { 
                if (e.TableCellIdentity.Column != null && e.TableCellIdentity.Column.Name == "SupplierID") 
                { 
                    e.Style.CellType = "CheckBox"; 
                } 
            } 
        } 
    } 
} 
 
 
 
Sample link: 
 
Regards, 
Piruthiviraj

Kevin
Replied On March 21, 2017 06:13 PM UTC

Hi Piruthiviraj,

Thanks for the update. I am having few more queries. In one page, I found the below code for getting parent record. 
Record parentRecord = e.TableCellIdentity.Table.TableModel.FilteredChildTable.ParentDisplayElement.ParentRecord;
In your code, you have mentioned some other way for getting parent record.
Record record = e.Style.TableCellIdentity.DisplayElement.GetRecord(); 
Record parentRecord = record.ParentChildTable.ParentNestedTable.ParentRecord; 

what is the exact difference between below two codes?
Record parentRecord = e.TableCellIdentity.Table.TableModel.FilteredChildTable.ParentDisplayElement.ParentRecord;
Record parentRecord = e.TableCellIdentity.DisplayElement.ParentChildTable.ParentNestedTable.ParentRecord;

Also as I like mentioned in my previous update, some of nested table cells having control and text. I have modified the sample that you shared and added exporting to excel options. But facing below issues.
1. Assigned text in cell which is having Checkbox control, but the text is not displayed in UI. If I exported, text is present in Excel.
2. Initially, On form load all my records is in collapse state. If I am exporting data to excel without doing expand, nested table cell values that are changed in QueryCellStyleInfo not exported properly. I dont have the need for expand the records before exporting. I have attaced the screenshots for this issues and modified sample project. 

Can you please share the solution for this?
- Kevin

Attachment: SampleModified_16d4ea98.zip

Piruthiviraj Malaimelraj [Syncfusion]
Replied On March 22, 2017 09:33 AM UTC

Hi Kevin, 
 
Thanks for the update. 
 
Query 
Response 
what is the exact difference between below two codes? 
Record parentRecord = e.TableCellIdentity.Table.TableModel.FilteredChildTable.ParentDisplayElement.ParentRecord; 
Record parentRecord = e.TableCellIdentity.DisplayElement.ParentChildTable.ParentNestedTable.ParentRecord; 
 
These two code will returns the same record. These are the ways to get the corresponding parent record from child table record. So you can use any one of those methods to get the parent record. 
 
 
 
 
 
 
 
 
 
 
Assigned text in cell which is having Checkbox control, but the text is not displayed in UI 
In order to set the text for checkbox , use the Style.Description property instead of Style.Text. 
 
Code example: 
e.Style.CellType = GridCellTypeName.CheckBox; 
e.Style.Description = "CustomText"; 
 
 
 
 
 
 
Initially, On form load all my records is in collapse state. If I am exporting data to excel without doing expand, nested table cell values that are changed in QueryCellStyleInfo not exported properly. 
We could able to understand your scenario. By default, the child table records can be accessed in QueryCellStyleInfo event when that child table is in expanded state only otherwise its records are not accessed in QueryCellStyleInfo event. So that the customization of child table records was not exported to excel if it is in Collapsed state. 
 
If you want to export the nested table customization which is done in QueryCellStyleInfo event, you need to expand the nested tables before exporting. 
 
In the attached sample, the nested tables are expanded before exporting and collapsed after exported the grid to excel. 
Code example: 
if (saveFileDialog.ShowDialog() == DialogResult.OK) 
{ 
    this.gridGroupingControl1.Table.ExpandAllRecords(); 
    ExportToExcel(saveFileDialog.FileName); 
    Process.Start(saveFileDialog.FileName); 
    this.gridGroupingControl1.Table.CollapseAllRecords(); 
} 
 
Sample link: 
 
Regards, 
Piruthiviraj

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

;