Overview

AbsGrid is an OCX for VB6 projects that display a very flexible grid control.
It's based upon the famous vbaccelerator sgrid 2 control

want to learn how to install and quickly use it ? click here.

And of course, it's free.

Features

I have enhanced sgrid2 by adding the following :
feature information/example
added a new event : CellClick CellClick(button, shift, row, col)
note that CellClick event is raised after the MouveDown event, and before eventually RequestEdit one.
This event is fired only for colomns that allow it (see ColumnFireClickEvent)
new property : ColumnFireClickEvent ColumnFireClickEvent("key") = true/false
allow to raise even CellClick on a column (default is false)
new property : ColumnNoEdit ColumnNoEdit("key") = true/false
disable editing for a column (default is false)

note also that you can use a new optional parameter of AddColumn to define noEdit
new property : noHighLightColor noHighLightColor = true/false
disable drawing of Highlight selector (default is false)
new sub TakeObjForEditing TakeObjForEditing(textboxctrlobject, row, col, left, top) place, resize and enable a text box control (or a listbox), to allow edition a cell content.
new property GroupRowColorMode GroupRowColorMode = 0 or 1 or 2
values are :
  • 0 : default (buggy : original sgrid2 behavior)
  • 1 : customized (take color from GroupRow[Back|Fore]Color property)
  • 2 : none, transparent
I preserved original (but buggy) behavior for sgrid2 for compatibility reasons.
new property : GroupExpandMode This property setup how groups are expanded.
GroupExpandMode= 0 or 1 or 2
  • ecgExpDblClick (0) : double click expand groups (default)
  • ecgExpClick (1) : single click expand groups
  • ecgExpNone (2) : it's not possible to expand groups
new property : InlineGrp InlineGrp set or get status about grouping column without group pannel.
value are true or false.
new property : InlineGrpFont you can define a specific font for grouped column, InlineGrpFont set or get this font.
new property : InlineGrpDisp define how inlined group are displayed, InlineGrpDisp allow to choose witch gadget are displayed or not (example :the [+] box...)
new function : InlineGrpActive InlineGrpActive(col1,[col2], [col3]) define one, two or three inlined-grouped column.
new function : ExpandAllGroups ExpandAllGroups([ecgExpanded]) expand all row of the group.
new function : Search Search(method,colkey,value,(byref) found) perform a multi purpose search on rows / cols.
it return an array of found value (row number)
This function supersed orginial search system that is not so flexible.
added a 3rd parameter to AutoHeightRow now support a 3rd parameter (optional, default is false) : bWithTextRow to take into account the textrow height.
now return the value (it's now function instead of sub) it now return computed height for the requested row.
Check this page for more informations about the new behavior.
fixed a bug at EndEdit function
optimisations performed a little bit of optimisation (and cleaning dead code) on UserControl_DblClick(), prop get Font()
added gradiant you can control the gradian mode with noMsImg32 property (true/false). gradiant can be drawn in raster mode (a little bit slower) or in DLL mode (if noMsImg32=false)
note that MsImg32.dll is not present on every system.
See this page to see information about gradiants
new property : InlineGrpTxtOffset InlineGrpTxtOffset = number very specific property to allow truncate text displayed of inlined-grouped (but full the text still used for sorting)

easier editing

I created a method to make life easier about editing cell content.
First place your grid (Grid1) and a textbox (Text1)

You can change textbox settings (appearance : flat...) and don't forget to change Visible property to False
now, in RequestEdit Event, handle the request :
Private Sub Grid1_RequestEdit(ByVal lRow As Long, ByVal lCol As Long,
                              ByVal iKeyAscii As Integer, bCancel As Boolean)

Grid1.TakeObjForEditing(Text1, lRow, lCol, Grid1.Left, Grid1.Top)

End Sub
This method will automatically move the Text1 control to the right place, place cell content into it, make it visible, and set focus on it to allow user starting editing. for nice stuff, create these two subs :
Private Sub Text1_KeyDown(KeyCode As Integer, Shift As Integer)
Select Case KeyCode
   Case 9, 13, 27 ' tab, return, escape
      Grid1.EndEdit
      KeyCode = 0
End Select
End Sub

Private Sub Text1_KeyPress(KeyAscii As Integer)
    Select Case KeyAscii ' Stop annoying beeps...
        Case 9, 13, 27
            KeyAscii = 0
    End Select
End Sub
and just don't forget to clean with :
Private Sub Grid_CancelEdit()
    Text1.Visible = False
End Sub
Note this is also working for Combo or ListBox control.

Search

result = AGrid1.Search(method, colkey, value, nb)
Perform a multi-purpose search on a column (defined with colkey)
list of accepted methods : The Search function return an array of all matched rows.
the array of long contain row id.
Example
Dim result() As Long, n as long
result = Grid.Search(col_InStrTextMatch,"colkey","patern",n)
for i=0 to n
 'do something about result(i)....
next

Inline grouping


As usual grouping system is buggy on SGrid2 (try to group cols with icon in header for example) and as it's not easy or possible to create group in the code itself, I decided to create function that help to make such group in code.
You don't have anymore to use AllowGrouping property
Now, you will use InlineGrp property.
See here how to create 2 cascaded group for column "c1" and "c4" :
Grid.inlineGrp=true
Grig.InlineGrpActive("c1","c4")
That's all ! how could be it more simplier ?

Optionally,
also you can define specific font for grouping : InlineGrpFont
and you can choose displayed gadget of group header... (a gradiant, a box...)
example of gadgets :
classic underlined gradiant (3)
classic [+]/[-] boxes (10)
double vertical gradiant (8)
vertical gradiant with triangles (80)
triangles (20)
example :
set f as new Stdfont
f.Name="Verdana"
f.italic=true
set Grid.InlineGrpFont=f
Grid.InlineGrpDisp=3 '3=gradiant
This example cover inlineGroup feature : download project source

examples download

sample project feature covered
prj1 (8kb) cell font and color, inline-grouping
prj2 (13kb) cell text property, rowheight, font
prj3 (52kb) cell font and color, cell icons and header icon, cell click event, grid selection property

to be continued...

download

binary file (absgrid.ocx) (472 kb)
complete absGrid source (104 kb)
note that sources file need to be cleaned up a little bit.

Link

AbsGrid is created upon vbaccelerator SGid2 source.
But vbAccelerator does not provide any support about AbsGrid.
vbAccelerator - Faster VB and .NET Code

Direct link to SGrid2 page from vbaccelerator.
SGrid2 Licence is "FREE SOURCE CODE - ENJOY!".

known issue

I found a bug that AllowGrouping with icon in the header may cause the application to crash. (to be check if this bug exist in sgrid2)

to be continued...