When I click on a cell, I get two ItemClick events. Is that intended?
Yes. To determine what area was clicked, you can inspect the AreaType parameter. The first ItemClick event will have an AreaType value of constSftTreeText, indicating that a mouse click occurred in a cell. The second event will have an AreaType value of constSftTreeCellGraphic or constSftTreeCellText. These values were new for 4.0 and allow you to distinguish between a generic click in a cell (constSftTreeText) or on the text or graphic component (constSftTreeCellText or constSftTreeCellGraphic) of the cell.
Can I limit cell editing for a column to just numbers?
Sure. If you want to limit cell editing, you can handle a control's events to control the type of data entered. For example, in our CellEditing sample, you could limit all input to just numbers by adding the following KeyPress event (to the Text1 control, not our tree control).
Similarly, you can handle all other events of each control to customize cell editing. If you require different data in different columns, you can simply add additional edit controls (for example) to handle different data types, each with its own event handlers.
While it is possible to limit input using this technique, it is often more advantageous to use more advanced controls for this purpose. For example, our SftMask/OCX edit control can be used to define much more sophisticated input types. The CellEditingII sample, also included in the demo, demonstrates this process.
SortDependents only sorts one column and I need to sort multiple columns. How can I accomplish this?
Sorting data in multiple columns is easily accomplished by sorting columns individually. The column with the least significant data is sorted first. Basically, you are sorting in reverse order of significance as far as the sort key is concerned. When you are sorting one column with multiple identical keys, the original order of the data (among the equal keys) is preserved. The sort algorithm guarantees that the original order is preserved when equal keys are sorted.
Assuming you have 3 columns, Street, City, ZIP Code, ZIP Code is the main key, followed by City, then Street. You would sort Street first, then City, then the ZIP Code column.
With SftTree/OCX it is also possible to implement a sort event SortCompare. When SortDependents is used with the SortType sortSftTreeEventWithIndex, the SortCompare event is called with the indices of the two items to be compared. The event implementation can then retrieve properties (of multiple columns) to build a complete key for sorting purposes. Sorting multiple columns using multiple SortDependents calls is more efficient, because a SortCompare event is called many times for each item and retrieving item properties to build a sort key will definitely affect the overall performance.
I'm using the tree control to display a list of items (like a list box), but I have a gap to the left of the text of the first column. How do I remove the gap?
Normally, the area to the left of the first cell's text is reserved for hierarchical display information, like tree lines, expand/collapse buttons, label pictures, etc. Most likely, the ButtonStyle property is set incorrectly. The following should remove the gap:
SftTree1.ButtonStyle = buttonsSftTreeNone
The tree control does not respond to the right mouse button. Why don't I get any events for the right mouse button?
By default, the middle and right mouse buttons are ignored by the tree control. You can change this behavior by using the LeftButtonOnly and LeftItemClickOnly properties.
The tree control does not respond to the left mouse button. Why don't I get any events for the left mouse button?
By default, the tree control ignores all mouse buttons and you can handle them using the events (ItemClick is usually useful). Or, if you want the tree control to handle expanding/collapsing items, set the AutoRespond property to True.
I'm displaying a popup menu in response to a right mouse click (using the MouseUp or ItemClick event). After the menu is done, the selection follows the mouse cursor and the next right mouse click has no effect. How can I fix this?
The tree control's internal handling of the right mouse button is interfering with your own processing. This can be easily solved by using the CancelMode method right before you display your popup menu. The CancelMode method tells the tree control to stop handling the event further.
Can I create the same type of tree control look as Windows Explorer?
Yes. The properties to look for are:
- ButtonStyle - Set the expand/collapse button image to the provided bitmap BUTTONS4.BMP (in the C:\Program Files\Softelvdm\SftTree OCX n.n\Bitmaps directory.
- TreeLineStyle - Set the connecting tree lines to "treeSftTreeDotted" to get a dotted line.
- SelectStyle - Set the display style of selected items to "selectSftTreeCell1". This will highlight only the text of the first column when an item is selected.
- TreeLineColor - Set the color property of the connecting tree lines to dark gray or the color "Button Shadow" as defined for the button shadow by Control Panel.