Change the Group Caption when the column is a ComboBox

When I drag a Combobox column to the group header the heading for each group uses the Value field value in the caption. In my example I have a Project column in my grid that is a combobox that has a drop down that lists projects. The value that is stored is the ProjectID field and that is an integer field so I get a Group head that looks like this when I use the Project column to group the data:



Where it lists the project value of "1" which is the ProjectID value . I would like it to display the actual Project name ( in this example it would be "Test Project") that is associated with that ProjectID for all of the project group headers. I have not been able to find a way to set the header text to the Project name value. Is there a setting that I am missing? If not, how can I accomplish this?

5 Replies

MA Mohanram Anbukkarasu Syncfusion Team January 11, 2021 12:31 PM UTC

Hi George, 

Thanks for contacting Syncfusion support.  

Data related operations like grouping, sorting and filtering will performed based on the MappingName of the columns. Based on the details you have provided we suspect that, the mapping name of the GridComboBoxColumn you are  mentioning should be ProjectID. That is why it displays the ProjectID value in the group caption.  Kindly share the code snippets you have used to create the GridComboBoxColumn. It will be more helpful for us to understand the exact scenario and to check for the possibilities to achieve this requirement at earlier.  

Regards, 
Mohanram A. 



GB George Busby January 12, 2021 01:53 AM UTC

Here is the code where I setup the combobox. I am using the autogeneration of the columns and trap for the fields that I know are ID fields that link to other tables ( Resource and Project) .

 Private Sub SfDataGrid2_AutoGeneratingColumn(sender As Object, e As AutoGeneratingColumnArgs) Handles SfDataGrid2.AutoGeneratingColumn
        If e.Column.MappingName = "ResourceID" Then
            e.Column.HeaderText = "Name"
            If TypeOf e.Column IsNot GridComboBoxColumn Then
                e.Column = New GridComboBoxColumn() With {.MappingName = "ResourceID", .HeaderText = "Name", .DisplayMember = "ResourceName", .ValueMember = "ResourceID", .DropDownStyle = DropDownStyle.DropDown, .AutoCompleteMode = AutoCompleteMode.SuggestAppend, .DataSource = Me.ResourceBindingSource}
            End If
        End If
        If e.Column.MappingName = "ProjectID" Then
            e.Column.HeaderText = "Project"
            If TypeOf e.Column IsNot GridComboBoxColumn Then
                e.Column = New GridComboBoxColumn() With {.MappingName = "ProjectID", .HeaderText = "Project", .DisplayMember = "ProjectName", .ValueMember = "ProjectID", .DropDownStyle = DropDownStyle.DropDown, .AutoCompleteMode = AutoCompleteMode.SuggestAppend, .DataSource = Me.ProjectBindingSource}
            End If
        End If
        If InStr(e.Column.MappingName, "Hrs") > 0 Then
            e.Column.HeaderText = "Hrs"
            e.Column.Width = 60
        ElseIf InStr(e.Column.MappingName, "%") > 0 Then
            e.Column.HeaderText = "%"
            e.Column.Width = 60
        End If

    End Sub

It does not do the end user any good to display the ProjectID value in the header. For it to make sense to an end user it needs to display the "DisplayMember" value so they will know what data is within each grouping. The ProjectID field is an integer field that is a foreign key to the Project table.

Here is how the grid looks when executed: ( The Name and Project ) columns are both ID fields that link to other tables.




MA Mohanram Anbukkarasu Syncfusion Team January 12, 2021 07:45 AM UTC

Hi George, 

Thanks for the update. 

We are able to understand the reported scenario from the provided code snippets. By default, the group caption text will be displayed based on MappingName of combo box column. This can be changed to display the DisplayMember using the GroupMode property of column as shown in the below given code example. 

Code example :  

this.sfDataGrid.AutoGeneratingColumn += SfDataGrid_AutoGeneratingColumn; 
 
private void SfDataGrid_AutoGeneratingColumn(object sender, Syncfusion.WinForms.DataGrid.Events.AutoGeneratingColumnArgs e) 
{ 
    if(e.Column.MappingName == "ShipCityID") 
    { 
        e.Column = new GridComboBoxColumn() 
        { 
            MappingName = "ShipCityID", 
            HeaderText = "Ship City", 
            ValueMember = "ShipCityID", 
            DisplayMember = "ShipCityName", 
            IDataSourceSelector = new CustomSelector(), 
            GroupMode = Syncfusion.Data.DataReflectionMode.Display 
        }; 
    } 
} 

We have prepared a sample using this code example and it is available in the following link for your reference.  


Please let us know if you require further assistance from us.  

Regards, 
Mohanram A. 



GB George Busby January 13, 2021 04:21 AM UTC

Thank you that worked.


MA Mohanram Anbukkarasu Syncfusion Team January 13, 2021 06:23 PM UTC

Hi George, 

Thanks for the update. 

We are glad to know that the provided solution worked at your end. Please let us know if you have any further queries on this. We are happy to help you. 

Regards, 
Mohanram A. 


Loader.
Up arrow icon