KB Article A2874
Visible to All Users

How to always display the summary item in the first visible column regardless of which column is the first

Description:
I currently have a summary count of all the entries in a particular column (i.e. total number of records) and it is currently shown at the bottom of this column in the footer. However, I want this summary to always be visible in the same location regardless of whether the user has dragged the column to another location. Is there any way to do this?

Answer:
Yes, you can achieve this task by handling the GridView’s DragObjectStart and DragObjectDrop events as shown below:

C#
private void gridView1_DragObjectDrop(object sender, DevExpress.XtraGrid.Views.Base.DragObjectDropEventArgs e) { if ((e.DragObject is DevExpress.XtraGrid.Columns.GridColumn) && (e.DropInfo is DevExpress.XtraGrid.Dragging.ColumnPositionInfo)) { if ((dragVisibleIndex == 0) || ((e.DropInfo as DevExpress.XtraGrid.Dragging.ColumnPositionInfo).Index == 0)) { (sender as DevExpress.XtraGrid.Views.Grid.GridView).Columns[dragAbsIndex].SummaryItem.SummaryType = DevExpress.Data.SummaryItemType.None; (sender as DevExpress.XtraGrid.Views.Grid.GridView).VisibleColumns[0].SummaryItem.SummaryType = DevExpress.Data.SummaryItemType.Count; } dragVisibleIndex = -1; dragAbsIndex = -1; } } int dragVisibleIndex = -1; int dragAbsIndex = -1; private void gridView1_DragObjectStart(object sender, DevExpress.XtraGrid.Views.Base.DragObjectStartEventArgs e) { if (e.DragObject is DevExpress.XtraGrid.Columns.GridColumn){ dragVisibleIndex = (e.DragObject as DevExpress.XtraGrid.Columns.GridColumn).VisibleIndex; dragAbsIndex = (sender as DevExpress.XtraGrid.Views.Grid.GridView).VisibleColumns[0].AbsoluteIndex; } } private void Form1_Load(object sender, System.EventArgs e) { oleDbDataAdapter1.Fill(dataSet11); }
Visual Basic
Private Sub GridView1_DragObjectDrop(ByVal sender As Object, ByVal e As DevExpress.XtraGrid.Views.Base.DragObjectDropEventArgs) Handles GridView1.DragObjectDrop If (TypeOf e.DragObject Is DevExpress.XtraGrid.Columns.GridColumn) And (TypeOf e.DropInfo Is DevExpress.XtraGrid.Dragging.ColumnPositionInfo) Then If (dragVisibleIndex = 0) Or CType(e.DropInfo, DevExpress.XtraGrid.Dragging.ColumnPositionInfo).Index = 0 Then CType(sender, DevExpress.XtraGrid.Views.Grid.GridView).Columns(dragAbsIndex).SummaryItem.SummaryType = DevExpress.Data.SummaryItemType.None CType(sender, DevExpress.XtraGrid.Views.Grid.GridView).VisibleColumns(0).SummaryItem.SummaryType = DevExpress.Data.SummaryItemType.Count End If dragVisibleIndex = -1 dragAbsIndex = -1 End If End Sub Private dragVisibleIndex As Integer = -1 Private dragAbsIndex As Integer = -1 Private Sub GridView1_DragObjectStart(ByVal sender As Object, ByVal e As DevExpress.XtraGrid.Views.Base.DragObjectStartEventArgs) Handles GridView1.DragObjectStart If TypeOf e.DragObject Is DevExpress.XtraGrid.Columns.GridColumn Then dragVisibleIndex = CType(e.DragObject, DevExpress.XtraGrid.Columns.GridColumn).VisibleIndex dragAbsIndex = CType(sender, DevExpress.XtraGrid.Views.Grid.GridView).VisibleColumns(0).AbsoluteIndex End If End Sub

See Also:
How to catch the moment when a column's position is changed
How to prevent end-users from hiding all grid columns

Disclaimer: The information provided on DevExpress.com and affiliated web properties (including the DevExpress Support Center) is provided "as is" without warranty of any kind. Developer Express Inc disclaims all warranties, either express or implied, including the warranties of merchantability and fitness for a particular purpose. Please refer to the DevExpress.com Website Terms of Use for more information in this regard.

Confidential Information: Developer Express Inc does not wish to receive, will not act to procure, nor will it solicit, confidential or proprietary materials and information from you through the DevExpress Support Center or its web properties. Any and all materials or information divulged during chats, email communications, online discussions, Support Center tickets, or made available to Developer Express Inc in any manner will be deemed NOT to be confidential by Developer Express Inc. Please refer to the DevExpress.com Website Terms of Use for more information in this regard.