by Brett Sheppard - GUI Computing
"Move over Big Jake. There's a new sheriff in town."
Yes, there sure is. True DBGrid 5 is here. The performance (always a strong point) is still there, and included are some mighty fine new features including an Array-based storage mode, a data-aware drop-down list box, reusable layouts and a bunch of new built-in styles, properties, database navigation and manipulation methods. So, let's take a look see.
"Dagnabbit! Used to be a time, when I was a boy, when using TrueGrid in unbound mode was a true test of programming skill. This new fangled technology…"
Without a doubt, the XArray, the new Array-based storage mode, is TDBGrid's best new feature. It is an effective and easy to use data source which takes a lot of the hard work out of such tasks as coding with unbound events. XArray is like a replacement for Visual Basic variant arrays but offers other functionality such as inserting and removing indices, allowing data to be preserved when redimensioning without any extra coding and inserting and deleting dimensions. Best of all, its usage is not restricted to True DBGrid 5.0.
I think the best way of demonstrating how easy it is to use is with an example. I am basically ripping the following straight out of the manual... something I can do because the quality of the manual has improved dramatically, with more detailed and clearer explanations of the grid's features along with suggestions for faster and efficient coding.
The code below will declare an XArray, define it's structure, populate the grid and attach it to a True DBGrid. (Note that I added two columns at design time, but this can also be done at runtime.)
Option Explicit Dim nRow As Long Dim nCol As Integer Dim C As TrueDBGrid50.Column Dim MyArray As New XArray Private Sub Form_Load() MyArray.ReDim 1, 20, 0, 3 ' Sets the structure of the array as a two dimensional array with 20 rows and 4 columns TDBGrid1.Array = MyArray ' Associates the grid with the XArray. With MyArray ' Populates the grid with the corresponding row and column number For nRow = .LowerBound(1) To .UpperBound(1) For nCol = .LowerBound(2) To .UpperBound(2) .Value(nRow, nCol) = "Row " & nRow & ", Column " & nCol Next nCol Next nRow End With TDBGrid1.Refresh ' Repaints the grid with the new data ' Because the refresh method does not clear the text within the floating editor window ' when the Marquee Style is set to FloatingEditor, it is necessary to set the EditActive ' property to True, then False so that you can clear that editor. TDBGrid1.EditActive = True TDBGrid1.EditActive = False End Sub
OK. So this little program won't set the world on fire, but it demonstrates how easy XArray is to use and it sure is easier than some of the previous DataModes used by True DB Grid.
"Hey, watch it. He's packing a hidden ListBox…"
Another impressive feature which has been added is the Data-Aware DropDown list box. This is a separate OCX that comes with True DB Grid. This drop down can only be used with True DB Grid and as it is a subset of the grid, it uses many of the events, methods and properties of it. I have to say, I found this really cool. You can use any of the data modes available and it's just so easy to use. To experiment with it, I placed a grid, the drop down box, and two data controls onto the form. I bound the first data control to Data1, the Drop Down to Data 2, added an extra column and changed its DropDown property to the DropDown control on the form. So with no lines of code I produced the following.
The Grid contains the contents of Data 1 as you expect. But when you choose the column you attached the grid to, a button appears. Upon selecting that button a list box with the fields of Data2 appears. You can then use the DropDownOpen and DropDownClose events to add the additional functionality you require such as selecting a record from the drop down and storing its key value in the grid.
"He's really cleanin' up this town fast with that snazzy designer gizmo."
Another addition to True DB Grid is that it now supports reusable layouts. You can now manipulate a grid into the appearance you need and then save that format to a binary file. This will save hours of time for programmers who have a certain style that they like their grids to be and who have previously been forced to perform repetitive tasks to achieve a presentation standard they are happy with. It will also enforce uniformity with a project by using the same layout throughout. Not only this, but end users can save their layout preferences and recall it next time they use the grid.
True DB Grid 5.0 has also seen the introduction of the Design Assistant. This is an addon which comes with the grid to, again, prevent us programmers from having to perform repetitive, time consuming tasks such as customizing color, font, and style properties for individual columns, creating fixed, nonscrolling columns using splits and applying a property value to all columns at once. This is not available in Visual Basic 4 however as it uses the extensibility model of VB5.
The Design Assistant operates when ever you click on True DBGrid or the Drop Down control and produces a list of all the properties for the columns that are to be used on the grid. You can then select a column and make it fixed, or change the color of the font, and by selecting an Apply button available in the add in, enforce that color to be used throughout all the columns. A powerful little tool that most programmers will like.
"That Miss Kitty sure is the purty one."
A lot of thought has also gone into making the appearance of True DB Grid easier to manipulate programmatically and easier for end users to understand. For example, multi-line displays are now available, which is excellent for grids with large numbers of columns. End users will love this new feature - no more scrolling from side to side.
Also supported are alternating row colors to give your grid extra readability, input masking using syntax almost identical to VB's format command, data-based formatting and multiple elements within a single cell.
Now, I wouldn't recommend the look below as a great piece of interface design, but it does illustrate the point.
"Think I'll mosey on down the store…"
All in all, this is an impressive upgrade. The XArray inclusion is a real winner as is the drop down list box. The new interface features, and their ease of programming, will please developers and users alike. And the revised manual makes actually using all these new features much easier.
Apex have done a great job to add all this and still maintain the sort of performance we've all come to love.
If you only buy one control this year, make it this one.