I am trying to fix the first 5 columns in the ultragrid and not allow the user to change that, similar to the freeze in Excel. I am using the following code in the MouseDown and MouseUp events. The problem is when the user clicks the pin on a particular column it blocks the change, but it still reorders the columns. I need the columns to stay in the original order.
Dim bFixedColumn As Boolean = False Private Sub UltraGrid1_MouseDown(sender As Object, e As MouseEventArgs) Handles UltraGrid1.MouseDown Dim grid As UltraGrid = TryCast(sender, UltraGrid) Dim controlElement As UIElement = grid.DisplayLayout.UIElement Dim elementAtPoint As UIElement = If(controlElement IsNot Nothing, controlElement.ElementFromPoint(e.Location), Nothing) Dim column As UltraGridColumn = Nothing While elementAtPoint IsNot Nothing Dim headerElement As FixedHeaderIndicatorUIElement = TryCast(elementAtPoint, FixedHeaderIndicatorUIElement) If headerElement IsNot Nothing AndAlso TypeOf headerElement Is Infragistics.Win.UltraWinGrid.FixedHeaderIndicatorUIElement Then 'setFixedColumns() column = TryCast(headerElement.GetContext(GetType(UltraGridColumn)), UltraGridColumn) bFixedColumn = column.Header.Fixed Exit While End If elementAtPoint = elementAtPoint.Parent End While End Sub Private Sub UltraGrid1_MouseUp(sender As Object, e As MouseEventArgs) Handles UltraGrid1.MouseUp Dim grid As UltraGrid = TryCast(sender, UltraGrid) Dim controlElement As UIElement = grid.DisplayLayout.UIElement Dim elementAtPoint As UIElement = If(controlElement IsNot Nothing, controlElement.ElementFromPoint(e.Location), Nothing) Dim column As UltraGridColumn = Nothing While elementAtPoint IsNot Nothing Dim headerElement As FixedHeaderIndicatorUIElement = TryCast(elementAtPoint, FixedHeaderIndicatorUIElement) If headerElement IsNot Nothing AndAlso TypeOf headerElement Is Infragistics.Win.UltraWinGrid.FixedHeaderIndicatorUIElement Then 'setFixedColumns() column = TryCast(headerElement.GetContext(GetType(UltraGridColumn)), UltraGridColumn) column.Header.Fixed = bFixedColumn Exit While End If elementAtPoint = elementAtPoint.Parent End While End Sub
I figured it out on my own.
Private Sub UltraGrid1_BeforeColPosChanged(sender As Object, e As BeforeColPosChangedEventArgs) Handles UltraGrid1.BeforeColPosChanged e.Cancel = True End Sub