Code Examples for 10Tec ActiveX Grid, 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 iKeyAscii As Integer, bCancel As Boolean, _
      sText As String, lMaxLength As Long)

   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)

   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:


Fitting row heights

In iGrid each row can have its own height. You can also automatically calculate the height of a row to display the cell texts without clipping. To do that for all rows in the grid, use code like this:

For iRow = 1 To grdCust.RowCount
   iGrid1.AutoHeightRow iRow

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"

Compatibility info for 10Tec ActiveX Grid »