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

Change false/true in GridGroupControl in close/open

Hello,

I'm very new in Syncfunsion and I need a little bit help.
When I use a normal DataGridView it is possible to change an bool value in a cell from true/false to for example in open/close.

I use this code in an DataGridView:

        private void adgvApplications_CellFormatting(object sender, DataGridViewCellFormattingEventArgs e)
        {
            var grid = (DataGridView)sender;
            if (grid.Columns[e.ColumnIndex].Name == "MyStatus")
            {
                if (e.Value != null)
                {
                    e.Value = (bool)e.Value ? "erledigt" : "offen";
                    e.FormattingApplied = true;                   
                }

            }
        }


How can I do this in a GridGroupControl?
Thanks and best regards
Thomas

12 Replies

PM Piruthiviraj Malaimelraj Syncfusion Team January 12, 2017 06:57 AM UTC

Hi Thomas, 

Thanks for your interest in Syncfusion products. 

We have analyzed your scenario and could able to understand your scenario. As per grid architecture, the boolean type column will displays as the CheckBox type column. So to change the looks of Boolean type column as textbox , set the CellType of that column to “TextBox” and CellValueType is to “string”. In order to change the “True/False” values to as you want (“Open/False”), QueryCellStyleInfo event can be used. In that event, the cell value can be changed by using e.Style.CellValue property. Please make use of the below code, 

Code example: 
this.gridGroupingControl1.TableDescriptor.Columns["Description"].Appearance.AnyRecordFieldCell.CellType = "TextBox"
this.gridGroupingControl1.TableDescriptor.Columns["Description"].Appearance.AnyRecordFieldCell.CellValueType = typeof(string); 

this.gridGroupingControl1.QueryCellStyleInfo += new Syncfusion.Windows.Forms.Grid.Grouping.GridTableCellStyleInfoEventHandler(gridGroupingControl1_QueryCellStyleInfo); 

void gridGroupingControl1_QueryCellStyleInfo(object sender, Syncfusion.Windows.Forms.Grid.Grouping.GridTableCellStyleInfoEventArgs e) 
    if (e.TableCellIdentity.Column != null && e.TableCellIdentity.Column.Name == "Description"  
        && e.TableCellIdentity.DisplayElement.Kind == Syncfusion.Grouping.DisplayElementKind.Record) 
    { 
        if (e.Style.CellValue.ToString() == "True"
        { 
            e.Style.CellValue = "Open"
        } 
        else 
            e.Style.CellValue = "Close"
    } 

Default Behaviour of Boolean type column: 
 

After Customization: 
 

Sample link: 

Please refer the below KB link for further references, 

Regards, 
Piruthiviraj


TH Thomas January 12, 2017 06:00 PM UTC

perfekt - thanks - super support


NK Neelakandan Kannan Syncfusion Team January 13, 2017 05:33 AM UTC

Hi Thomas, 

Thanks for your update. 

We are glad to hear from you that your reported scenario has been resolved. Please let us know if you need further assistance on this.  

Regards, 
Neelakandan 



TH Thomas January 27, 2017 12:18 PM UTC

Dear member,

please help us to solve the problem described below.

When I group this column (I move this column to "Drag a column header here to group by thar column") I see in the grouped row (Header) true/false. Is it also possible to change it to open/close?

Thanks in advance an best regards
Thomas

Attachment: 20170127_GGC_9f20c037.zip


AR Amal Raj U Syncfusion Team January 30, 2017 09:04 AM UTC

Hi Thomas, 

Thanks for your update. 

As we have customized the cell value of the Records since the background data for the “Description” column contains cell value of True/False, we have to customize the cell value for the GroupCaptionCell also. Please make use of the below code, 

Code Example 
//Event Subscription. 
this.gridGroupingControl1.QueryCellStyleInfo += new GridTableCellStyleInfoEventHandler(gridGroupingControl1_QueryCellStyleInfo); 

void gridGroupingControl1_QueryCellStyleInfo(object sender, Syncfusion.Windows.Forms.Grid.Grouping.GridTableCellStyleInfoEventArgs e) 
    if (e.TableCellIdentity != null && e.TableCellIdentity.TableCellType == GridTableCellType.GroupCaptionCell
    { 
        if (e.TableCellIdentity.GroupedColumn != null && e.TableCellIdentity.GroupedColumn.Name == "Description") 
        { 
            if (e.Style.CellValue.ToString().Contains("True")) 
                e.Style.CellValue = e.Style.CellValue.ToString().Replace("True", "Open"); 
            else if(e.Style.CellValue.ToString().Contains("False")) 
                e.Style.CellValue = e.Style.CellValue.ToString().Replace("False", "Close"); 
        } 
    } 
 
Sample Link 
 
Regards, 
Amal Raj U. 



TH Thomas January 31, 2017 10:10 AM UTC

Hello,

thanks for the support.

But I have one more question. When I have a second table (1 = Germany, 2 = Austria, 3 = Swiss) and I would replace the CountryId from the main table with the name from the Country-Table?

BR Thomas


PM Piruthiviraj Malaimelraj Syncfusion Team February 1, 2017 01:12 PM UTC

Hi Thomas, 

Thanks for the update. 

We have analyzed your scenario but we are little bit unclear with your reported scenario. Could you please provide us with the below details, 

·         In your update, “second table” is mentioned nested table or any other? , please provide the more details about “Second table” that you are using in your sample. 
·         Please provide us with the screen shots or video or simple sample which represents your scenario that you want to achieve. 

It would be more helpful for us to provide the exact details at the earliest. 

Regards, 
Piruthiviraj 



AB Arda Beyazoglu February 1, 2017 01:26 PM UTC

Hello,

I have to do the same thing on DataBoundGrid, but QueryCellStyleInfo event does not exist in DataBoundGrid control. How could you achieve the same thing here ?


PM Piruthiviraj Malaimelraj Syncfusion Team February 2, 2017 04:33 AM UTC

Hi Arda, 

Thanks for your interest in Syncfusion products. 

We could able to understand your scenario and the QueryCellInfo event can be accessed through GridDataBoundGrid.Model. GridDataBoundGrid does not have support for grouping, so group caption could not be changed. Please make use of the below code, 

Code example: 
this.gridDataBoundGrid1.Model.QueryCellInfo += new GridQueryCellInfoEventHandler(Model_QueryCellInfo); 
void Model_QueryCellInfo(object sender, GridQueryCellInfoEventArgs e) 
{ 
    if (e.ColIndex == 2 && e.RowIndex >= this.gridDataBoundGrid1.TopRowIndex) 
    { 
        e.Style.CellType = "TextBox"; 
        e.Style.CellValueType = typeof(string); 
        if (e.Style.CellValue.ToString() == "True") 
        { 
            e.Style.CellValue = "Open"; 
        } 
        else 
            e.Style.CellValue = "Close"; 
    } 
} 

Sample link: 

Please refer the below UG for further references, 

Regards, 
Piruthiviraj 
 



TH Thomas February 2, 2017 12:01 PM UTC

Hello,

I have a table "Vehicle" with my vehicles and inside a column "GlobalCountryId". I have a second table "Countries" that holds the Countries. When I group the column Country (Land) I see only Land: 1, Land: 2, Land: 3, but I would like see Land: Deutschland, Land: Österreich, Land: Schweiz. I would like to replace the Country ID with the real Country-Name.

But the country-list can be long and it's not possible/difficult to replace all with IF-Queries. Is there a solution?

Thanks
Thomas

Attachment: GroupColumn_f609c24f.zip


AB Arda Beyazoglu February 2, 2017 12:22 PM UTC

Thanks. It works like a charm.


PM Piruthiviraj Malaimelraj Syncfusion Team February 3, 2017 05:32 AM UTC

Hi Thomas, 

Thanks for the update. 

We have analyzed your scenario with provided screenshots. It seems that, the column which has value member(countryId) and display member (countryname) is grouped in your sample project. By default, in GridGroupingControl , the grouping is performed based on ValueMember , not by DisplayMemeber. So , the caption text shows value member(countryId). This the default behaviour of GridGroupingControl. In order to customize the GroupCaptionText with display text, QueryCellStyleInfo event can be used. In that event, the countryId will be replaced by countryName. Please make use of the below code, 
 
Code example: 
this.gridGroupingControl1.QueryCellStyleInfo += new Syncfusion.Windows.Forms.Grid.Grouping.GridTableCellStyleInfoEventHandler(gridGroupingControl1_QueryCellStyleInfo); 
void gridGroupingControl1_QueryCellStyleInfo(object sender, Syncfusion.Windows.Forms.Grid.Grouping.GridTableCellStyleInfoEventArgs e) 
{ 
    if (e.TableCellIdentity != null && e.TableCellIdentity.TableCellType == GridTableCellType.GroupCaptionCell) 
    { 
        if (e.Style.TableCellIdentity.GroupedColumn != null && e.Style.TableCellIdentity.GroupedColumn.Name == "Land") 
        { 
            if (e.TableCellIdentity.DisplayElement.ParentGroup.GroupTypedListRecords.Count > 0) 
            { 
                Record groupRecord = e.TableCellIdentity.DisplayElement.ParentGroup.GroupTypedListRecords[0]; 
                string cellValue = groupRecord.GetValue("Land").ToString(); 
                string displayText = ""; 
                DataTable table = this.gridGroupingControl1.TableDescriptor.Columns["Land"].Appearance.AnyRecordFieldCell.DataSource as DataTable; 
                foreach (DataRow dr in table.Rows) 
                { 
                    if (dr[0].ToString() == cellValue) 
                    { 
                        displayText = dr[1].ToString(); 
                        break; 
                    }  
                } 
                if (displayText != null) 
                    e.Style.CellValue = e.Style.CellValue.ToString().Replace(cellValue.ToString(), displayText); 
            } 
        } 
    } 
} 
 
 
 
Sample link: 
 
Regards, 
Piruthiviraj 


Loader.
Up arrow icon