The following are a common set of Frequently Asked Questions (FAQ's) about TopGrid.

Q1. What is the difference between TtsGrid and TtsDbGrid?
A TtsDbGrid is a data bound grid whereas TtsGrid is not. TtsDbGrid has a DataSource property to associate a TQuery or TTable or TClientDataSet (and many other 3rd party datasets) to the grid. The contents of the dataset will be automatically displayed and managed within the grid. The TtsGrid is not databound and is extremely powerful and flexable to present data in different arrangements. You can use the StoreData property to have TtsGrid manage the storage of data that is typed into the cells, or you can manage the data yourself in underlying arrays, lists or datasets and then present the data within the OnCellLoaded event - this is known as virtual grid mode and provides excellent performance.

Q2. How can I change the color of specific rows at runtime?
Two different methods are available - (1) Create a procedure to set the RowColor[row] property of the grid or (2) Use the OnGetDrawInfo event to look at row contents and specify the color (and font) for each cell of the row during the paint operation. If the logic is fast, then the OnGetDrawInfo is recommended, otherwise, use the RowColor to set the color only once.

Q3. Can I assign individual cell hints?
There is no built in mechanism for cell hints within TopGrid. We are looking at this feature for a future release, but in the meantime we recommend that the CellFromXY call be used within OnMouseOver event to condifionally force a cell hint.

Q4. Why doesn't the OnHeadingClick work?
The OnHeadingClick only goes off ONLY when the HeadingButton property is set to hbCell or hbButton. The default property is hbNone meaning that the OnHeadingClick event will not go off.

Q5. How can I sort the rows in the grid?
The only way to sort the rows of a databound grid is to close the dataset, add a sort, and then re-open the dataset. An unbound grid can only be sorted by changing the sort order of the underlying data - the OnCellLoaded logic is yours to control. Using the TopGrid's ability to move rows upwards and downwards in the grid is not recommended for sorting as it will yield poor performance for large numbers of rows.

Q6. Why isn't the vertical scrollbar reflecting the number of records in the grid?
You get a the three positional scrollbar thumb (top-middle-bottom) when the grid's DataSetType property is set to dstStandard, and the attached dataset does not support sequence numbers for its records (Dataset.IsSequenced returns false). Typically this occurs when you are not using a BDE dataset but a third party of self-made dataset instead. In that case, the grid's DatasetType is automatically set to dstStandard, and if the dataset's IsSequenced then returns false, you get a three positional scrollbar.There's no way around this, exept to have the makers of the dataset implement the sequenced records. If you're using a standard Delphi BDE dataset (TTable or TQuery), set the DataseType to dstBDE to have a normal scrollbar.

Q7. How can I select the entire row in the grid?
Selecting the RowBar at the far left of the grid (it must be visible) will select the entire row regardless of the GridMode property. Setting the GridMode property to gmBrowse (vs gmEdit) will automatically select the entire row when clicking a cell. You will have to use Ctrl or Shift to select additional rows.

Q8. Why do I get an error when I reference the cell value using tsDbGrid1.Cell[2, 3]?
This is a common error for many first time users of TopGrid. When referencing the cell of an unbound grid (ie. TtsGrid), both the column and row values of the array are integers. For example, tsGrid1.Cell[31, 44]. A databound grid cell is referenced by a column number and the dataset bookmark (not an integer). For example, tsDbGrid1.Cell[2, Query1.Bookmark]. There is no way to reference the Nth row of the grid just as it is not possible to reference the Nth row of the dataset.

Q9. What is the difference between a virtual grid and a stored data grid (ie. StoreData = True)?
A virtual grid provides high performance because it does not allocate duplicate memory in the grid for your data, and cell data is only required (and if designed correctly loaded as well) until the cell is scrolled into view. The data for a large grid with StoreData = True would all be loaded before the grid is presented and drawn on the screen.

Q10. How can I save the grid layout and restore it later (at runtime)?
TopGrid has several useful built in methods for saving and restoring the grid layout. Different aspects of the grid layout can be stored or all of the grid, column, row and cell properties can be saved and retrieved. Even the data can be saved with the layout information. Layout information can either be saved/restored to/from the registry using SaveToRegistry/LoadFromRegistry or to/from a file using SaveToStream, SaveToFile and LoadFromStream and LoadFromFile.

Q11. How do I get the images in the grid to be transparent?
The TransparentColor property is used to specify the background color when drawing images.

Q12. How can I access the even numbered rows in by data bound grid?
Unfortunately, since a databound grid is buffered internally for increased performance and rows in a dataset are referenced by bookmark and not by a integer value, there is no technique to access even or odd rows in the grid.

Q13. Does TopGrid only work with BDE datasets?
No!. The TtsDbGrid will also function with any 3rd party dataset that descends from the TDataSet primitive class. There are VERY few (in fact I am not even sure what they are) 3rd party datasets that do not function with TopGrid.

Q14.How do I set the picture in TtsMask so I can use negative numbers in the tsDbgrid?
Use the mask [;-]#*2[#][.#[#]] The ';' is an escape character, which allows the character following to be taken literally and not as a special symbol. The square brackets indicate an optional character.

Q15. How do I programmatically move to a different cell in the grid and have it appear to the user?
The best technique to move the cell position within the grid is to use the CurrentCell object and the MoveTo method to change the Current cell within the grid. To make sure that the current cell is scrolled into view for the user, use the method.

Q16. How do I configure a combo dropdown to automatically pull back the data value but display a different data column?
There are quite a different number of ways to configure dropdown and lookup columns in the grid. The OnComboInit, OnComboGetValue and several other combo based events are present to handle the more complex circumstances. The easiest (no coding) mechanism to create a dropdown on a coded value column is to create a Calculated LookupField on the dataset that is associated with the lookup dataset, the coded column and then displays the corresponding display value (eg. customer_states table, customer_state_cd and customer_state_name columns). Add the calculated lookup field to the grid instead of the coded value (eg. customers.customer_status_cd), change the ButtonType of the column to btCombo and specify the Combo AutoLookup property to True (this means no combo datasource is required as it is built into the lookup field itself). YOU'RE DONE! The combo drop down will display the contents of the lookup dataset, and when a selection is made the coded value will automatically be captured.

Q17.How do I disable the grid from repainting and flickering when my code is doing numerous calculations and adjustments to the dataset?
Version 2.01 has a property on the grid called EnableRedraw that is set to false and true within a try..finally block to disable grid painting when frequent operations on the grid are being performed. This will substantially improve performance during these mass operations. Version 2.20 has added two methods that are more well known in the VCL community called BeginUpdate and EndUpdate.

Q18.Can I configure TopGrid to show some cells in a column to be text and others to be a combo dropdown?
Yes. All you need to do is to add some code to the OnRowLoaded event to interpret various cell values for that row, and then programmitcally set the CellButtonType for the cell to be either btCombo or btNone.

Q19. Is it possible to have a non-bound column in a data-aware grid that has a check box in it?
Yes. A TtsDbGrid generally starts out with several columns from a bound dataset. Blank columns can be added within the designer. You will then need to add the necessary logic in the OnCellLoaded event to populate the value for the non-bound cells. And if you all editing of the cell, you will need to trap this within the OnEndCellEdit event to update the associated data structure in your program. If you do not do this, then the next OnCellLoaded call will put the original value back into the cell (essentially right away).

Q20.Why are the checkboxes grayed out even when the AllowGrayed property is false?
The AllowGrayed property only states that the user cannot force a null value (grayed out). A checkbox will be gray if the cell value is NULL or equal to ''. To make sure the value is not grayed out, a value must be supplied.

Q21.How do I easily clear out the contents of a Stored Data grid without having to loop thru each cell?
The easiest way to clear out the cell contents is to set the Rows property to zero (0). If you want the same number of rows, then set the Rows property back to the number of rows that was originally in the grid. Use the BeginUpdate and EndUpdate methods to eliminate any flicker.