Class
DesktopGrid
Grid
Description
Draws a scrollable grid of DesktopContainer controls.
Properties
Name |
Type |
Read-Only |
Shared |
|---|---|---|---|
✓ |
|||
✓ |
|||
✓ |
|||
✓ |
|||
Methods
Name |
Parameters |
Returns |
Shared |
|---|---|---|---|
type As String |
|||
type As String |
|||
column As Integer |
|||
x As Integer, y As Integer, width As Integer, height As Integer, immediately As Boolean = False |
|||
row As Integer |
|||
Events
Name |
Parameters |
Returns |
|---|---|---|
cell As DesktopContainer |
||
column As Integer |
||
base As DesktopMenuItem, x As Integer, y As Integer |
||
selectedItem As DesktopMenuItem |
||
obj As DragItem, action As DragItem.Types |
||
obj As DragItem, action As DragItem.Types |
||
x As Integer, y As Integer, obj As DragItem, action As DragItem.Types |
||
obj As DragItem, action As DragItem.Types |
||
key As String |
||
key As String |
||
x As Integer, y As Integer, deltaX As Integer, deltaY As Integer |
||
row As Integer |
||
Enumerations
DesktopGrid.GridLineStyles
GridLineStyles
The locations that where lines should be drawn between cells.
Name
Both
Horizontal
None
Vertical
Property descriptions
DesktopGrid.Active
Active As Boolean
Indicates whether the DesktopGrid is active.
Active is False when the control's window is not in the foreground. When a DesktopWindow is deactivated, its controls are automatically deactivated unless AllowAutoDeactivate is set to False.
This property is read-only.
DesktopGrid.AllowAutoDeactivate
AllowAutoDeactivate As Boolean
Determines whether the control should be deactivated (on macOS) when the parent window is deactivated. The default is True.
DesktopGrid.AllowCellSelection
AllowCellSelection As Boolean
DesktopGrid.AllowTabStop
AllowTabStop As Boolean
If True, the control is in the Tab Order and accepts the focus when the user tabs into it. The default is True. If False, the user cannot tab into it to give it the focus. However, the control can gain the focus by other means, such as the user's clicking on it or by setting the focus in code.
This example removes the control from the Tab Order:
Me.AllowTabStop = False
DesktopGrid.BackgroundColor
BackgroundColor As ColorGroup
The color of the background of the cells.
DesktopGrid.ColumnHeaderHeight
ColumnHeaderHeight As Integer
The height of the column header area.
DesktopGrid.DataSource
DataSource As GridDataSource
The source of the data to be used by the cells of the DesktopGrid control.
DesktopGrid.Enabled
Enabled As Boolean
Determines if the control should be enabled when the owning window is opened.
A disabled control cannot be clicked and cannot receive the focus.
This example disables the control.
Me.Enabled = False
DesktopGrid.GridLineStyle
GridLineStyle As GridLineStyles
The style used to draw the lines between cells.
DesktopGrid.Handle
Handle As Ptr
Returns a handle to the control.
This property is read-only.
For interfacing with Mac APIs using Declares, DesktopGrid.Handle returns NSViews (except for DesktopToolbar).
On Windows returns the HWND of the control.
On Linux it returns a GtkWidget.
The following gets a handle to the control.
Var p As Ptr = Me.Handle
DesktopGrid.HasColumnHeader
HasColumnHeader As Boolean
Determines if the column header is visible or not.
DesktopGrid.HasRowHeader
HasRowHeader As Boolean
Determines if the row header is visible or not.
DesktopGrid.Height
Height As Integer
The height (in points) of the control.
This example sets the height of the control to 100:
Me.Height = 100
DesktopGrid.LastSelectedColumnIndex
LastSelectedColumnIndex As Integer
The index of the last selected column.
This property is read-only.
DesktopGrid.LastSelectedRowIndex
LastSelectedRowIndex As Integer
The index of the last selected row.
This property is read-only.
DesktopGrid.Left
Left As Integer
The distance from the left side of the control to the left side of its containing window or container.
The following example moves the control 100 points from the left side of the window:
Me.Left = 150
DesktopGrid.LockBottom
LockBottom As Boolean
Determines whether the bottom edge of the control should stay at a set distance from the bottom edge of the parent control, if there is one, or the owning window.
This property can be set in the control's Inspector. The following example sets it in code.
Me.LockBottom = True
DesktopGrid.LockLeft
LockLeft As Boolean
Determines whether the left edge of the control should stay at a set distance from the left edge of the parent control, if there is one, or the owning window.
LockLeft and Locktop default to True when you add a new control to a window. Existing controls will be altered only if LockRight and/or LockBottom are not set. LockLeft has no effect unless LockRight is True.
This property can be set in the control's Inspector. The following example sets it in code.
Me.LockLeft = True
DesktopGrid.LockRight
LockRight As Boolean
Determines whether the right edge of the control should stay at a set distance from the right edge of the parent control, if there is one, or the owning window.
This property can be set in the control's Inspector. The following example sets it in code.
Me.LockRight = True
DesktopGrid.LockTop
LockTop As Boolean
Determines whether the top edge of the control should stay at a set distance from the top edge of the parent control, if there is one, or the owning window.
LockTop and LockLeft default to True when you add a control to a window. Existing controls will be altered only if LockRight and/or LockBottom are not set. LockTop has no effect unless LockBottom is True.
This property can be set in the control's Inspector. The following example sets it in code.
Me.LockTop = True
DesktopGrid.MouseCursor
MouseCursor As MouseCursor
The cursor to be displayed while the mouse is within the control and both the DesktopApplication and DesktopWindow class's MouseCursor properties are Nil.
If the DesktopApplication class's MouseCursor property is not Nil or the DesktopWindow's MouseCursor property is not Nil, then any control's MouseCursor property is ignored. You can use a cursor stored in the Cursors module. On Macintosh, you can also obtain a MouseCursor from a resource file.
This line in the Opening event of the control sets the default cursor to the finger pointer.
Me.MouseCursor = System.Cursors.FingerPointer
DesktopGrid.PanelIndex
PanelIndex As Integer
If the control has been placed on a DesktopTabPanel or DesktopPagePanel control, this is the panel (page/tab) that the control is on. If the control is not on a panel, it returns -1.
The first panel is numbered zero. If the control has been placed on a panel of a DesktopTabPanel or DesktopPagePanel control, it returns the panel number. If the control is not on a DesktopPagePanel or DesktopTabPanel, it returns -1. If you change the PanelIndex to a nonexistent panel, the control will disappear until you give it a PanelIndex value that corresponds to a panel that exists.
If you are looking to change the currently selected panel (page/tab), use DesktopPagePanel.
This code displays the panel index of the control that is on the page.
MessageBox(Me.SelectedPanelIndex.ToString)
DesktopGrid.Parent
Parent As Object
Used to get and set the control's parent control or window.
If the control is on the window, the Parent will be the Window. If the control is on the container, the Parent will be the container. If the control is completed enclosed by another control, the Parent will be that DesktopUIControl.
If you do not want the enclosing control to be the parent, set the Parent property of that control to Nil to make it the Window.
If the parent control is somehow in another window, an InvalidParentException will occur.
The following example sets the parent of the control to the window.
Me.Parent = Nil
DesktopGrid.RowHeaderWidth
RowHeaderWidth As Integer
The width of the header for all rows.
DesktopGrid.Tooltip
Tooltip As String
Text of help message displayed as a Windows or Linux tooltip or macOS help tag.
The tip/tag is displayed when the user hovers the mouse cursor over the control.
This example adds a tooltip to a control:
Me.Tooltip = "Click to bark."
DesktopGrid.Top
Top As Integer
The distance from the top of the control to the top of its containing window or container.
This example sets the top of the control to 140 points from the top of the window:
Me.Top = 140
DesktopGrid.Transparent
Transparent As Boolean
Determines whether the control is transparent on Windows. The default is False. Has no effect on macOS or Linux.
Transparent controls draw more slowly and use more memory in order to cache the background. Unless you absolutely require transparency, leave this set to False.
For projects that were created prior to 2018r1, this property defaults to True to emulate previous behavior. Consider changing it to False to improve performance if you do not require transparency.
DesktopGrid.Visible
Visible As Boolean
Determines whether the control is visible when its owning window is opened. The default is True: the control is visible.
The following code makes the control invisible:
Me.Visible = False
DesktopGrid.Width
Width As Integer
The width (in points) of the control.
The following example resizes the control:
Me.Width = 200
Method descriptions
DesktopGrid.AcceptFileDrop
AcceptFileDrop(type As String)
Permits documents of type FileType to be dropped on the control. FileType must be a file type that you defined in via the FileType class or the File Type Sets Editor.
This code in the Opening event makes it possible for the user to drop either a picture or a file that is a jpeg image. The File Type Sets editor was used to define the image/jpeg file type. It is one of the Common File Types that is available in the editor.
Me.AcceptPictureDrop Me.AcceptFileDrop("image/jpeg")To restrict file drops to just folders (and not files), you can put this code in the DragEnter event:
If Not obj.FolderItem.IsFolder Then Return True
DesktopGrid.AcceptPictureDrop
AcceptPictureDrop
Permits pictures to be dropped on the control.
If a control should accept pictures in a drag and drop, then AcceptPictureDrop needs to be called prior to the drop. Typically, it is in the Opening event of the control itself. For example, the line:
Me.AcceptPictureDropin the Opening event of the control that will receive the dragged pictures is needed. When the picture is dropped, the DropObject event is called and this is where you will put your code to handle the drop.
Opening Event:
Me.AcceptPictureDropDropObject Event:
If obj.PictureAvailable Then Me.Backdrop = obj.Picture End If
DesktopGrid.AcceptRawDataDrop
AcceptRawDataDrop(type As String)
Permits data (of the Type specified) to be dropped on the control.
The following specfies a generic file type defined in the File Type Sets editor.
Me.AcceptRawDataDrop("????")
DesktopGrid.AcceptTextDrop
AcceptTextDrop
Permits text to be dropped on the control.
This line in the Opening event of a control that can accept dragged text.
Me.AcceptTextDrop
DesktopGrid.CellSelectedAt
CellSelectedAt(row As Integer, column As Integer) As Boolean
CellSelectedAt(row As Integer, column As Integer, Assigns value As Boolean)
DesktopGrid.SelectedCells
CellsSelected As Pair()
DesktopGrid.Close
Close
Closes a control.
Closing a control permanently removes the control from memory, making it impossible to access. You can close both non-indexed controls and indexed controls. When you close an indexed control, the indexes for the remaining controls will shift downward so that the indexes start with zero and are consecutive.
The following code closes the control. When this is executed from a visible control, the control disappears from the window.
Me.Close
DesktopGrid.ColumnSelectedAt
ColumnSelectedAt(column As Integer) As Boolean
ColumnSelectedAt(column As Integer, Assigns value As Boolean)
DesktopGrid.ColumnsSelected
ColumnsSelected As Integer()
Returns an array of indexes of the columns that are currently selected.
DesktopGrid.DrawInto
DrawInto(g As Graphics, left As Integer, top As Integer)
Draws the control into the graphics context represented by g.
DesktopGrid.Refresh
Refresh(immediately As Boolean = False)
Redraws the portion specified of the contents of the control the next time the OS redraws the control or immediately if True is passed.
If you are calling this so frequently that you experience a slowdown in your code, pass True for the immediately parameter.
Calling this method causes the Render event to fire.
Refresh the entire area immediately:
Me.Refresh(True)Note
If you are updating the window in a tight loop, consider instead using App.DoEvents.
Refresh(x As Integer, y As Integer, width As Integer, height As Integer, immediately As Boolean = False)
Redraws the portion specified of the contents of the control the next time the OS redraws the control or immediately if True is passed.
Refresh a portion of the area the next time the OS redraws the control:
Me.Refresh(100, 150, 200, 300)
DesktopGrid.Reload
Reload
Reloads the cells content from the DataSource.
DesktopGrid.RowSelectedAt
RowSelectedAt(row As Integer) As Boolean
RowSelectedAt(row As Integer, Assigns value As Boolean)
DesktopGrid.RowsSelected
RowsSelected As integer()
Returns an array of indexes of the rows that are currently selected.
DesktopGrid.SetFocus
SetFocus
If applicable and the control is enabled, sets the focus to the DesktopGrid. KeyDown events are directed to the control.
If the control cannot get the focus on the platform on which the application is running, SetFocus does nothing. The SetFocus method of the DesktopWindow class or the ClearFocus method can be used to remove the focus from the control that currently has the focus, leaving no control with the focus.
Note
On macOS, you need Full Keyboard Access turned on in System Preferences (Keyboard->Shortcuts) in order to manually set focus to non-text controls.
The following example in the Opening event sets the focus to the that control. If another control has the focus when this line is executed, then the user sees this control gets the focus.
Me.SetFocus
Event descriptions
DesktopGrid.CellPressed
CellPressed(cell As DesktopContainer)
The user has clicked on the cell.
DesktopGrid.Closing
Closing
The control is closing.
DesktopGrid.ColumnHeaderPressed
ColumnHeaderPressed(column As Integer)
The user clicked on the column.
DesktopGrid.ConstructContextualMenu
ConstructContextualMenu(base As DesktopMenuItem, x As Integer, y As Integer) As Boolean
This event is called when it is appropriate to display a contextual menu for the control.
This event handler is the recommended way to handle contextual menus because this event figures out whether the user has requested the contextual menu, regardless of how they did it. Depending on platform, it might be in the MouseUp or MouseDown event and it might be a right+click or by pressing the contextual menu key on the keyboard, for example.
Base is analogous to the menu bar for the contextual menu. Any items you add to Base will be shown as menu items. If you return False, the event is passed up the parent hierarchy.
If you return True, the contextual menu is displayed. The parameters x and y are the mouse locations. If the event was fired because of a non-mouse event, then x and y are both set to -1. See the example of a contextual menu in the following section.
The following ConstructContextualMenu event handler builds a menu with three menu items plus a submenu with three additional menu items.
' Add some items base.AddMenu(New DesktopMenuItem("Test 1")) base.AddMenu(New DesktopMenuItem("Test 2")) base.AddMenu(New DesktopMenuItem("Test 3")) ' Add a Separator base.AddMenu(New DesktopMenuItem(DesktopMenuItem.TextSeparator)) ' Add a sub menu Var submenu As New DesktopMenuItem("SubMenu") submenu.AddMenu(New DesktopMenuItem("SubMenu Test 1")) submenu.AddMenu(New DesktopMenuItem("SubMenu Test 2")) submenu.AddMenu(New DesktopMenuItem("SubMenu Test 3")) base.AddMenu(submenu) ' Add a Separator base.AddMenu(New DesktopMenuItem(DesktopMenuItem.TextSeparator)) Return True
DesktopGrid.ContextualMenuItemSelected
ContextualMenuItemSelected(selectedItem As DesktopMenuItem) As Boolean
Fires when a contextual menuitem selectedItem was selected but the MenuItemSelected event and the MenuHandler for the DesktopMenuItem did not handle the menu selection.
This event gives you a chance to handle the menu selection by inspecting the menuitem's Text or Tag properties to see which item was selected. Use this in conjunction with ConstructContextualMenu if you have not specified the MenuItemSelected event or the Menu Handler for the items on the contextual menu. See the example of a contextual menu in the examples for the DesktopUIControl class.
Return True if this event has handled the item the user chose from the contextual menu. Returning False will cause the control's parent to execute its ContextualMenuItemSelected event. This can be handy if you have the same contextual menu for several controls who share the same Parent (several on the same window for example). By returning False you can handle them all in a single event.
This simple event handler displays the value of the selected menu item.
If selectedItem <> Nil Then MessageBox(selectedItem.Text) Return True
DesktopGrid.DragEnter
DragEnter(obj As DragItem, action As DragItem.Types) As Boolean
Fires when the passed DragItem enters the DesktopGrid.
Returns a Boolean. Return True from this event to prevent the drop from occurring.
The Action parameter specifies the type of drag action.
To restrict file drops to just folders (and not files), you can put this code in the DragEnter event:
If Not obj.FolderItem.IsFolder Then Return True
DesktopGrid.DragExit
DragExit(obj As DragItem, action As DragItem.Types)
Fires when the passed DragItem exits the DesktopGrid.
The Obj parameter is the item being dragged. The Action parameter specifies the type of drag action.
DesktopGrid.DragOver
DragOver(x As Integer, y As Integer, obj As DragItem, action As DragItem.Types) As Boolean
Fires when the DragItem is over the DesktopGrid.
The Obj parameter is the object being dragged. The coordinates x and y are relative to the DesktopGrid. Returns a Boolean. Return True from this event to prevent the drop from occurring.
The Action parameter specifies the type of drag action, which is typically done by holding down a modifier key (Shift, Alt, Option, Command, etc.) while doing the drag.
DesktopGrid.DropObject
DropObject(obj As DragItem, action As DragItem.Types)
The item represented by Obj has been dropped on the control.
The Obj parameter is the object being dragged. The Action parameter specifies the type of drag action.
The following DropObject event handler can handle either a dropped picture or a dropped file. The type of file that it can handle needs to have been specified in a call to AcceptFileDrop prior to the drop, for example, in the Opening event.
If Obj.PictureAvailable Then Me.Image = obj.Picture ElseIf Obj.FolderItemAvailable Then Me.Image = Picture.Open(obj.FolderItem) End If
DesktopGrid.FocusLost
FocusLost
The DesktopGrid has lost the focus.
This property must be set to True for the DesktopGrid to be capable of getting then losing the focus.
Note
On macOS, controls other than text fields and lists will accept and lose focus only if the full keyboard access option is enabled in System Preferences/Keyboard.
DesktopGrid.FocusReceived
FocusReceived
The DesktopGrid has received the focus and has a selection rectangle around it.
This property must be set to True for the DesktopGrid to be capable of getting the focus.
Note
On macOS, controls other than text fields and lists will accept focus only if the full keyboard access option is enabled in System Preferences/Keyboard.
DesktopGrid.KeyDown
KeyDown(key As String) As Boolean
DesktopGrid.KeyUp
KeyUp(key As String)
Fires when the passed Key is released in the control that has the focus.
It is not guaranteed to be the same key that received the KeyDown event.
DesktopGrid.MouseDown
MouseDown(x As Integer, y As Integer) As Boolean
The mouse button was pressed inside the control's region at the location passed in to x, y.
This event fires repeatedly while the mouse button is being held down.
The coordinates x and y are local to the control, i.e. they represent the position of the mouse click relative to the upper-left corner of the DesktopGrid.
Return True if you are going to handle the MouseDown. In such a case:
The Pressed event, if any, will not execute and the state of the object will not change.
You will receive the MouseUp event.
If you return False, the system handles the MouseDown so the MouseUp event handler does not get called.
The MouseDown event uses the DragItem constructor when the user drags the contents of the control. It is:
Var d As DragItem d = New DragItem(Self, Me.Left, Me.Top, Me.Width, Me.Height) d.Picture = Me.Image d.Drag ' Allow the drag
DesktopGrid.MouseDrag
MouseDrag(x As Integer, y As Integer)
The mouse button was pressed inside the control and moved (dragged) at the location local to the control passed in to x, y.
This event fires repeatedly while the mouse button is down regardless of whether or not the mouse coordinates are changing.
This event will not occur unless you return True in the MouseDown event.
DesktopGrid.MouseEnter
MouseEnter
The mouse has entered the area of the control.
DesktopGrid.MouseExit
MouseExit
The mouse has left the area of the control.
DesktopGrid.MouseMove
MouseMove(x As Integer, y As Integer)
The mouse has moved within the control to the coordinates passed. The coordinates are local to the control, not to the window.
DesktopGrid.MouseUp
MouseUp(x As Integer, y As Integer)
The mouse button was released. Use the x and y parameters to determine if the mouse button was released within the control's boundaries.
Note
This event will not occur unless you return True in the MouseDown event. The return value is ignored.
The parameters x and y are local coordinates, i.e. they represent the position of the mouse click relative to the upper-left corner of the DesktopGrid. Mouse clicks that are released to the left or above a control are negative.
DesktopGrid.MouseWheel
MouseWheel(x As Integer, y As Integer, deltaX As Integer, deltaY As Integer) As Boolean
The mouse wheel has been moved.
The parameters X and Y are the mouse coordinates relative to the control that has received the event. The parameters DeltaX and DeltaY hold the number of scroll lines the wheel has been moved horizontally and vertically, as defined by the operating system. DeltaX is positive when the user scrolls right and negative when scrolling to the left. DeltaY is positive when the user scrolls down and negative when scrolling up.
Returns a Boolean. Return True to prevent the event from propagating further.
DesktopGrid.Opening
Opening
The control is about to be displayed. Use this event to initialize a control.
The Opening event is called after the Constructor.
Be warned that initializing control property values using the Constructor instead of the Opening event may result in those property values being overwritten by what is set in the Inspector. For best results, use the Opening event for control initialization rather than the control Constructor.
If the control is supposed to handle drag and drop, you need to tell it which type of item it needs to be able to handle. The following example informs the control that pictures and files can be dropped on it. The type of the file it needs to support is specified via the File Types Editor.
Sub Opening() Me.AcceptPictureDrop Me.AcceptFileDrop("JPEG") End Sub
DesktopGrid.RowHeaderPressed
RowHeaderPressed(row As Integer)
The user has clicked on a row header.
DesktopGrid.SelectionChanged
SelectionChanged
Occurs when any time a row, column or cell is selected or deselected.
Notes
In order for a DesktopGrid control to be capable of displaying a virtually unlimited number of cells, it must load data into these cells dynamically when the control is initially drawn, as the user scrolls and as code executes that changes which cells are displayed. This is done by having an instance of a class that implements the GridDataSource interface. This instance will then be called by the DesktopGrid control via the methods defined by the interface which then takes requests for cells from the DesktopGrid control and returns the data from the ultimate source (a database or some other source) allowing the DesktopGrid to populate its cells.
To implement this interface:
Choose an existing class such as the DesktopWindow or DesktopContainer the DesktopGrid is on or add a new class to your project.
In the Inspector, click the Interfaces button then in the Interfaces dialog box that appears, click the checkbox next to GridDataSource to select it.
In the Interfaces dialog box, click the OK button to select the interface for the class.
This will add the methods to your class that will be called when the DesktopGrid need data.
See GridDataSource for information on how to populate these methods.
Typically in the Opening of the DesktopGrid you would then assign the instance of class that is implementing the GridDataSource to the DataSource property of the DesktopGrid control.
Compatibility
Project Types |
Desktop |
Operating Systems |
All |
See also
DesktopUIControl parent class; GridDataSource interface, DesktopGrid with Database Example project