Code Examples for 10Tec iGrid, Part II

(iGrid Control Tour, Step 6 of 6)

Controlling the editing

You can use many iGrid events to control the editing process in this grid. Among them are RequestEdit, BeforeCommitEdit, AfterCommitEdit and CancelEdit.

When the user attempts to edit any cell, the RequestEdit method is fired. You can check some conditions in this event and to decide whether the user will edit the cell. For instance, you can protect the cells in the second column from editing using the following code:

Private Sub iGrid1_RequestEdit(_
      ByVal lRow As Long, ByVal lCol As Long, _
      ByVal lCharCode As Long, bCancel As Boolean, _
      sText As String, lMaxLength As Long, _
      eTextEditOpt As ETextEditFlags)

   If lCol = 2 Then
      bCancel = True
   End If
End Sub

The next event, BeforeCommitEdit, is fired when the user attempts to save the edited cell text. You can prevent a cell in the column with the "sum" key of entering any non-positive numbers with the help of the following lines of code:

Private Sub iGrid1_BeforeCommitEdit(_
      ByVal lRow As Long, ByVal lCol As Long, _
      eResult As EEditResults, _
      ByVal sNewText As String, vNewValue As Variant, _
      ByVal lConvErr As Long, ByVal bCanProceedEditing As Boolean, _
      ByVal lComboListIndex As Long)

   If iGrid1.ColKey(lCol) = "sum" Then
      If Val(vNewValue) < 0 Then
         MsgBox "Only positive numbers!"
         eResult = igEditResProceed
      End If
   End If
End Sub

The eResult parameter of the BeforeCommitEdit method allows to control how iGrid works while the user attempts to commit cell changes. By default, this parameter has the igEditResCommit value. It means that iGrid will save any entered data in the cell value. If you assign igEditResCancel to this parameter, all user input will be aborted. The last value, igEditResProceed, allows to proceed the editing process without its completion.

A couple of useful built-in combo box methods

iGrid automatically calculates the height of each combo box item based on its contents (icon and/or item text) and combo box font. It also fits the height of the drop-down list to display up to 8 items simultaneously. You can specify the maximum number of visible items in the drop-down portion of a combo box using the MaxHeightInItems property of ComboObject. For instance, you can set the height of the Combo1 combo box so its drop-down part will display up to six items simultaneously:

iGrid1.Combos("Combo1").MaxHeightInItems = 6

In addition you can automatically adjust dropdown width of your combo box based on the longest text width of its items using the following statement:

iGrid1.Combos("Combo1").AutoAdjustWidth

Fitting row heights

In iGrid each row can have its own height. You can also automatically adjust the height of a row to display the cell texts without clipping with the AutoHeightRow method. To do this for all rows in the grid in one call, use the AutoHeightRows method:

iGrid1.AutoHeightRows

How to ensure the required cell is visible

The iGrid control has many useful methods that lighten your programming work. Among them is the EnsureVisible method. This method checks whether the specified cell is visible in the viewable part of the grid. If not, this method automatically scrolls the grid so the specified cell is visible. You can be sure that the cell in the "title" column in the third row is visible on the screen using the following statement:

iGrid1.EnsureVisible 3, "title"

vbAccelerator SGrid and the history of iGrid ActiveX »