Add sfDataGrid caption summary

Hi,

First I want to thank you for your great help with other controls and your quick answers in previous period.

  1. My first question is about adding Caption summary to Group sfDataGrid.

I am using Visual Studio 2022 and writing code in vb.net. Syncfusion controls and VS are up-to-date.

I added sfDataGrid control through Designer. Grid is populated with data from SQL Server Database. I converted DataTable to List and connected it to DataSource (Me.SfDataGrid1.DataSource = ListaKP)

I added setings for sfDataGrid in code like this:


        Me.SfDataGrid1.ShowGroupDropArea = False


        Me.SfDataGrid1.Columns("Klasa").AllowGrouping = True

        Me.SfDataGrid1.Columns("Grupa").AllowGrouping = True

        Me.SfDataGrid1.Columns("Sintetika").AllowGrouping = True


        Me.SfDataGrid1.GroupColumnDescriptions.Add(New GroupColumnDescription() With {.ColumnName = "Klasa"})

        Me.SfDataGrid1.GroupColumnDescriptions.Add(New GroupColumnDescription() With {.ColumnName = "Grupa"})

        Me.SfDataGrid1.GroupColumnDescriptions.Add(New GroupColumnDescription() With {.ColumnName = "Sintetika"})


        Me.SfDataGrid1.AutoSizeColumnsMode = AutoSizeColumnsMode.Fill


        Me.SfDataGrid1.Columns("Godina").Visible = False

        Me.SfDataGrid1.Columns("Klasa").Visible = False

        Me.SfDataGrid1.Columns("Grupa").Visible = False

        Me.SfDataGrid1.Columns("Sintetika").Visible = False


        Me.SfDataGrid1.Columns("Konto").Width = Math.Round(Me.SfDataGrid1.Width * 2 / 24, 0)

        Me.SfDataGrid1.Columns("NazivKonta").Width = Math.Round(Me.SfDataGrid1.Width * 11 / 24, 0)

        Me.SfDataGrid1.Columns("Duguje").Width = Math.Round(Me.SfDataGrid1.Width * 3 / 24, 0)

        Me.SfDataGrid1.Columns("Potrazuje").Width = Math.Round(Me.SfDataGrid1.Width * 3 / 24, 0)

        Me.SfDataGrid1.Columns("Saldo").Width = Math.Round(Me.SfDataGrid1.Width * 3 / 24, 0)


        Me.SfDataGrid1.AutoSizeColumnsMode = AutoSizeColumnsMode.LastColumnFill


        Me.SfDataGrid1.Columns("Konto").CellStyle.HorizontalAlignment = HorizontalAlignment.Left

        Me.SfDataGrid1.Columns("NazivKonta").CellStyle.HorizontalAlignment = HorizontalAlignment.Left

        Me.SfDataGrid1.Columns("Duguje").CellStyle.HorizontalAlignment = HorizontalAlignment.Right

        Me.SfDataGrid1.Columns("Potrazuje").CellStyle.HorizontalAlignment = HorizontalAlignment.Right

        Me.SfDataGrid1.Columns("Saldo").CellStyle.HorizontalAlignment = HorizontalAlignment.Right


        Me.SfDataGrid1.Style.CellStyle.Font = New GridFontInfo(New Font("Roboto", 10.0F))


        Me.SfDataGrid1.Columns("Konto").AllowEditing = False

        Me.SfDataGrid1.Columns("NazivKonta").AllowEditing = False

        Me.SfDataGrid1.Columns("Duguje").AllowEditing = False

        Me.SfDataGrid1.Columns("Potrazuje").AllowEditing = False

        Me.SfDataGrid1.Columns("Saldo").AllowEditing = False


        Me.SfDataGrid1.Columns("Konto").HeaderText = "Konto"

        Me.SfDataGrid1.Columns("NazivKonta").HeaderText = "Naziv konta"

        Me.SfDataGrid1.Columns("Duguje").HeaderText = "Duguje"

        Me.SfDataGrid1.Columns("Potrazuje").HeaderText = "Potrazuje"

        Me.SfDataGrid1.Columns("Saldo").HeaderText = "Saldo"


        Me.SfDataGrid1.Style.HeaderStyle.Font = New GridFontInfo(New Font("Roboto", 10.0F))

        Me.SfDataGrid1.Style.HeaderStyle.Font.FontStyle = Drawing.FontStyle.Bold


        Me.SfDataGrid1.Style.HeaderStyle.BackColor = Color.SandyBrown


        Me.SfDataGrid1.Columns("Konto").AllowHeaderTextWrapping = True

        Me.SfDataGrid1.Columns("NazivKonta").AllowHeaderTextWrapping = True

        Me.SfDataGrid1.Columns("Duguje").AllowHeaderTextWrapping = True

        Me.SfDataGrid1.Columns("Potrazuje").AllowHeaderTextWrapping = True

        Me.SfDataGrid1.Columns("Saldo").AllowHeaderTextWrapping = True


        Me.SfDataGrid1.HeaderRowHeight = 32


        Me.SfDataGrid1.SelectionMode = GridSelectionMode.Single


        Me.SfDataGrid1.Style.SelectionStyle.BackColor = Color.PeachPuff


Everything worked fine and I got this picture

Image_8742_1715154429573

That is what I wanted to get

Then I have tried to add Caption Summary for this sfDataGrid. So I added next code:

        Me.SfDataGrid1.GroupCaptionTextFormat = "{ColumnName}: {Key}"


        Dim captionSummaryRow As New GridSummaryRow()

        captionSummaryRow.Name = "CaptionSummary"

        captionSummaryRow.ShowSummaryInRow = False

        captionSummaryRow.TitleColumnCount = 3

        captionSummaryRow.Title = "{ColumnName}: {Key}"


        ' Creates the GridSummaryColumn1.

        Dim summaryColumn1 As New GridSummaryColumn()

        summaryColumn1.Name = "Duguje"

        summaryColumn1.Format = "{Sum:c}"

        summaryColumn1.MappingName = "Duguje"

        summaryColumn1.SummaryType = SummaryType.DoubleAggregate


        ' Creates the GridSummaryColumn2.

        Dim summaryColumn2 As New GridSummaryColumn()

        summaryColumn2.Name = "Potrazuje"

        summaryColumn2.Format = "{Sum:c}"

        summaryColumn2.MappingName = "Potrazuje"

        summaryColumn2.SummaryType = SummaryType.DoubleAggregate


        ' Creates the GridSummaryColumn2.

        Dim summaryColumn3 As New GridSummaryColumn()

        summaryColumn3.Name = "Saldo"

        summaryColumn3.Format = "{Sum:c}"

        summaryColumn3.MappingName = "Saldo"

        summaryColumn3.SummaryType = SummaryType.DoubleAggregate


        ' Adds the summary column in the SummaryColumns collection.

        captionSummaryRow.SummaryColumns.Add(summaryColumn1)

        captionSummaryRow.SummaryColumns.Add(summaryColumn2)

        captionSummaryRow.SummaryColumns.Add(summaryColumn3)


        ' Initializes the caption summary row.

        Me.SfDataGrid1.CaptionSummaryRow = captionSummaryRow


I used this code from your example from the internet sight.

Some lines are OK and they are working (like first one -  GroupCaptionTextFormat ) but VS is showing error

"Severity Code Description Project File Line Suppression State

Error BC30451 'SummaryType' is not declared. It may be inaccessible due to its protection level. EM_2024_1 D:\VB Net\VB Net Projects\Aktuelno\EM-2024_1\EM-2024_1\KF_KontniPlan.vb 380 Active"


I tried to find example project to see what is the difference in codes and I did find. But the example is totally with different code and syntax. So I looked in imports and found this


' Imports that are shown in My project generated through Design


Imports Syncfusion.WinForms.DataGrid

Imports Syncfusion.WinForms.DataGrid.Enums

Imports Syncfusion.WinForms.DataGrid.Styles


' Imports that are shown in your vb.net example for datagrid summary


Imports Syncfusion.Grouping

Imports Syncfusion.Windows.Forms.Grid

Imports Syncfusion.Windows.Forms.Grid.Grouping

 

I tried to implement this import but that causes other mistakes in code.

Please can you help me to solve problem - adding Caption Summary for Group in sfDataGrid - Displaying  column summary with title.


2. My second question is about changing border color of focused cell for selected row.

I manage to set background color for selected row in sfDataGrid and I got this

Image_4454_1715155384744


I set up Peach colour for background but on focused cell is still Blue border. How to change that through code.

If you need additional data I will sand you.

Thank you
Sabian

3 Replies 1 reply marked as answer

MA Manikanda Akash Munisamy Syncfusion Team May 9, 2024 02:38 PM UTC

Hi Sabin,

Query 1: CaptionSummary throws the exception

 

We have analyzed the reported scenario in our end, we did not face any error while setting CaptionSummaryRow. Please find the attached sample and confirm whether we have properly replicated the scenario.

As per your error message, SummaryType is not accessible. Could you please confirm whether you have referred "Syncfusion.Data.WinForms" properly. And in our attached sample SummaryType is working fine without any errors. Could you please review our sample and let us know if you need further assistance.

 

Query 2: CurrentCell styling.

 

To override current cell style border, please refer to the below user guide documentation.

Selection | DataGrid Control for Windows Forms | Syncfusion

This section explains about the selection feature and it's customization in datagrid control for windows forms.


Regards,

Manikanda Akash


Attachment: DataGrid_WF_NET60_24b88c91.zip

Marked as answer

SS Sabian Sirius May 10, 2024 07:43 AM UTC

Hi  Manikanda,


Query 1: CaptionSummary throws the exception


I am sorry that I hasn't been more precise. 

I am working in vb.net with NET Framework 4.81. 

Nevertheless, I analyzed your example and notice that I haven't referred to "Syncfusion.Data". When I did that Visual Studio shows no error. 


Query 2: CurrentCell styling


It is OK when I add 

Me.sfDataGrid1.Style.CurrentCellStyle.BorderColor = Color.SandyBrown
Me.sfDataGrid1.Style.CurrentCellStyle.BorderThickness = GridBorderWeight.Thick

I got what I want


Image_2907_1715324587563


Thank you very much for fast answer


Best wishes,

Sabian



SP Sreemon Premkumar Muthukrishnan Syncfusion Team May 13, 2024 04:28 PM UTC

Hi Sabian Sirius, 

We glad that the reported issue gets resolved. If you have any further assistance, please let us know. 

Regards,

Sreemon Premkumar M.


Loader.
Up arrow icon