Type | Description |
The LayoutChanged event notifies your application once a column is resized or moved by drag and drop. Also, the LayoutChanged event may be fired if the item's position is changed by drag and drop using the AutoDrag property.
Syntax for LayoutChanged event, /NET version, on:
private void LayoutChanged(object sender) { } Private Sub LayoutChanged(ByVal sender As System.Object) Handles LayoutChanged End Sub |
private void LayoutChanged(object sender, EventArgs e) { } void OnLayoutChanged() { } void __fastcall LayoutChanged(TObject *Sender) { } procedure LayoutChanged(ASender: TObject; ); begin end; procedure LayoutChanged(sender: System.Object; e: System.EventArgs); begin end; begin event LayoutChanged() end event LayoutChanged Private Sub LayoutChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles LayoutChanged End Sub Private Sub LayoutChanged() End Sub Private Sub LayoutChanged() End Sub LPARAMETERS nop PROCEDURE OnLayoutChanged(oGrid) RETURN |
<SCRIPT EVENT="LayoutChanged()" LANGUAGE="JScript"> </SCRIPT> <SCRIPT LANGUAGE="VBScript"> Function LayoutChanged() End Function </SCRIPT> Procedure OnComLayoutChanged Forward Send OnComLayoutChanged End_Procedure METHOD OCX_LayoutChanged() CLASS MainDialog RETURN NIL void onEvent_LayoutChanged() { } function LayoutChanged as v () end function function nativeObject_LayoutChanged() return |
Since, the LayotChanged event may be fired on different scenarios, you can distingue the action that previously occurs by storing the ItemFromPoint and/or ColumnFromPoint during the MouseDown event like in the following VB sample:
Dim iItemFromPointMouseDown As Long Dim iColumnFromPointMouseDown As Long Private Sub Form_Load() iItemFromPointMouseDown = 0 iColumnFromPointMouseDown = -1 End Sub Private Sub Grid1_LayoutChanged() If (iItemFromPointMouseDown <> 0) Then Debug.Print "Items section changed" Else If (iColumnFromPointMouseDown <> -1) Then Debug.Print "Columns section changed" Else Debug.Print "Others" End If End If iItemFromPointMouseDown = 0 iColumnFromPointMouseDown = -1 End Sub Private Sub Grid1_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single) Dim c As Long, hit As HitTestInfoEnum With Grid1 iItemFromPointMouseDown = .ItemFromPoint(-1, -1, c, hit) iColumnFromPointMouseDown = .ColumnFromPoint(-1, -1) End With End Sub
The sample displays:
"Columns section changed" if any change occurs in the Columns section, like moving a column to a new position or resizing the column.
"Items section changed", if the user drags an item to a new position using the AutoDrag property on exAutoDragPosition, exAutoDragPositionKeepIndent and exAutoDragPositionAny
You can use the LayoutChanged event to save the columns position and size for future use. Use the Width property to retrieve the column's width. Use the Position property to retrieve the column's position. The Visible property specifies whether a column is shown or hidden. Use the ColumnAutoResize property to specify whether the visible columns fit the control's client area.
There are two options to avoid losing the columns proportions:Private Sub Form_Resize() On Error Resume Next If ScaleWidth / Screen.TwipsPerPixelX > 64 Then With Grid1 .Left = 0 .Top = 0 .Width = ScaleWidth .Height = ScaleHeight End With End If End Sub
Option Explicit Dim nFit As Long Private Declare Function PeekMessage Lib "user32" Alias "PeekMessageA" (lpMsg As MSG, ByVal hwnd As Long, ByVal wMsgFilterMin As Long, ByVal wMsgFilterMax As Long, ByVal wRemoveMsg As Long) As Long Private Declare Function TranslateMessage Lib "user32" (lpMsg As MSG) As Long Private Declare Function DispatchMessage Lib "user32" Alias "DispatchMessageA" (lpMsg As MSG) As Long Private Const PM_REMOVE = &H1 Private Type POINTAPI x As Long y As Long End Type Private Type MSG hwnd As Long message As Long wParam As Long lParam As Long time As Long pt As POINTAPI End Type Private Sub Form_Load() nFit = 0 onGridResize Grid1 End Sub Private Sub Form_Resize() On Error Resume Next nFit = nFit + 1 With Grid1 .Left = 0 .Top = 0 .Width = ScaleWidth .Height = ScaleHeight End With fit Grid1 nFit = nFit - 1 End Sub Private Sub Grid1_LayoutChanged() If (nFit = 0) Then onGridResize Grid1 End If End Sub Private Sub fit(ByVal g As EXGRIDLibCtl.Grid) nFit = nFit + 1 With g If (.ColumnAutoResize) Then .BeginUpdate .ColumnAutoResize = False Dim c As EXGRIDLibCtl.Column For Each c In .Columns c.Width = c.Data Next .ColumnAutoResize = True .EndUpdate End If End With waitToProcessMessages nFit = nFit - 1 End Sub Private Sub onGridResize(ByVal g As EXGRIDLibCtl.Grid) Dim c As Object With g If (.ColumnAutoResize) Then For Each c In .Columns c.Data = c.Width Next End If End With End Sub Private Sub waitToProcessMessages() Dim m As MSG While PeekMessage(m, 0, 0, 0, PM_REMOVE) TranslateMessage m DispatchMessage m Wend End Sub