DatGridview Grand Total and horizontal scrollbar

  • Thread starter Thread starter Claudio111
  • Start date Start date
C

Claudio111

Guest
Hi All,

I'm trying to add Grand Total to a DataGridView numeric columns

The solution i'm trying to build is to add one more DGV (DGVTotal) with non columns headers and just one row that will be filled with total for specific columns. (TODO)

The Original DGV is in Panel (in red color) . In the main form I call class DGVTOTALI that will add the DGVTotal to the Panel and clone DGVOriginal columns and DGVOriginalRowTemplate

Everything works for now.

The DGVTotali class code is the following


Public Class DGVTotali

Private DgvTotal As DataGridView

Private MyPanel As Panel
Private WithEvents DGVOriginale As DataGridView


Public Sub New(ByRef pDGV As DataGridView)
DGVOriginale = pDGV
DgvTotal = New DataGridView
MyPanel = DGVOriginale.Parent
ShowDGVTotale()
AddDGVOriginaleEventHandler()
End Sub

Public Sub ShowDGVTotale()

DgvTotal.SuspendLayout()
' clear DGVTotal columns since this sub is called several times in eventhandler
' to rebuild DGVTotal
DgvTotal.Columns.Clear()
DgvTotal.DataSource = Nothing

MyPanel.AutoScroll = False
MyPanel.VerticalScroll.Visible = False
MyPanel.HorizontalScroll.Visible = True


' set size and location for DGVTotale

Dim sX = DGVOriginale.Width
DgvTotal.RowTemplate = DGVOriginale.RowTemplate
Dim sY1 = 25
DgvTotal.Size = New Size(sX, sY1)

Dim locY = DGVOriginale.Location.Y + DGVOriginale.Height + 5
Dim locX = DGVOriginale.Location.X
DgvTotal.Location = New Point(locX, locY)
DgvTotal.Anchor = AnchorStyles.Bottom + AnchorStyles.Left + AnchorStyles.Right

DgvTotal.ColumnHeadersVisible = False

' hide DGVScrollBar
DgvTotal.ScrollBars = ScrollBars.None
DGVOriginale.ScrollBars = ScrollBars.Vertical
' set DGVTotal Style
DgvTotal.CellBorderStyle = DGVOriginale.CellBorderStyle
DgvTotal.RowHeadersVisible = DGVOriginale.RowHeadersVisible
DgvTotal.BorderStyle = DGVOriginale.BorderStyle

' Clone DGVOriginal columns to DGVTotal Columns
For Each dgvc As DataGridViewColumn In DGVOriginale.Columns
DgvTotal.Columns.Add(dgvc.Clone())
Next

' Add DGVTotal to panel
MyPanel.Controls.Add(DgvTotal)
DgvTotal.ResumeLayout()

End Sub

Public Sub AddDGVOriginaleEventHandler()
AddHandler DGVOriginale.ColumnWidthChanged, AddressOf DataGridView_ColumnWidthChanged
' TODO OTHER DGV EVENT FOR RESIZING AND TOTALS
End Sub

Public Sub DataGridView_ColumnWidthChanged()
MyPanel.Controls.Remove(DgvTotal)
ShowDGVTotale
End Sub

End Class




Now I hide Horizontal scrollbar for both Original and Total DGV and I added a Horizontal Scroll bar to the panel.


What I wish is that when I scroll the Panel Horizontal scrollbar, both DGV should be scrolled horizontally.

How to do it?

Following is the Image of the Form

1299849.png

Continue reading...
 
Back
Top