10Tec Company
top bar image
Free Newsletter
Your e-mail:


iGrid Control Tour - Code Samples (I)

In this section we want to demonstrate how you can solve some particular tasks using iGrid methods, properties and events. The name of the grid is assumed to "iGrid1".

How to save and restore iGrid layout

It is considered as the rule of a good form if your application saves order positions and width of each column of each grid and restores these parameters when the user launch your application next time. iGrid automates this task by providing the LayoutCol property to developers. To implement such functionality, save anywhere the string value returned by this property, and assign it to this property later when your application is starting next time. For instance, to store the columns layout in the Windows Registry for the current user, write the following line of code in the Form_Unload event for each grid you using in your application:

SaveSetting "MyApplicationID", "Layout", "Columns", iGrid1.LayoutCol

Then you can restore columns layout for that user in the Form_Load event using the following statement:

iGrid1.LayoutCol = GetSetting("MyApplicationID", "Layout", "Columns")

By assigning the stored value to the LayoutCol property you restore order, width and visibility for each column of your grid. The LayoutSort property allows you to save and restore the current sorting of the grid (including numerated sort icons) even if you have sorted iGrid by several columns.

Populating and formatting cells

Assume that there is a column with the "title" key in your grid. To display text in the first cell of this column and highlight it by the red color, write the following code:

iGrid1.CellValue(1, "title") = "YourTitle"
iGrid1.CellForeColor(1, "title") = RGB(255, 0, 0)

Notice that you can refer the specified column by numeric index and by the key of this column.

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
How to browse an ADO recordset

The iGrid control was designed to replace standard ListView and FlexGrid controls with an editable grid and to allow developers more sophisticated displays to be set up. But this version of the control allows to browse ADO recordsets. To populate iGrid with the data from the rsCust ADO recordset, use the FillFromRS method:

iGrid1.FillFromRS rsCust

Once this statement has been executed, your grid displays all columns and all records from your recordset. If you execute the statement above when the grid has some columns, the keys of this columns will be used as field names from your recordset and iGrid will display the data only from these columns.

 
In this section:
Download Demo
  Back to Top
Visit our partners:
Visual Basic News & Information Source Tools and components for software developers ViewSlip - Perfest products for your business! Quality Tools for Serious Microsoft Developers Shareup Networks Downloads vbAccelerator.com Download software from TopShareware.com Shareware and Freeware downloads and tested, rated and reviewed software submitted by software author.
Everything Visual Basic, from Visual Basic 3 to Visual Basic Xml Upload.com: a web service for promoting and selling software online
© 10Tec Company. Last updated: 20 Mar 2008