Q: Can I change the font or color of a cell?
Sure. Using GetCellInfo/SetCellInfo, you can provide colors or a font for a cell in the SFTTREE_CELL structure, as in
SFTTREE_CELLINFOPARM CellInfo;
CellInfo.version = 6;
CellInfo.index = cell_index_to_change;
CellInfo.iCol = column_number_to_change;
m_Tree.GetCellInfo(&CellInfo);
CellInfo.Cell.hFont = a_font_handle;
CellInfo.Cell.colorBg = RGB(0,0,255); /* Blue background */
CellInfo.Cell.colorFg = RGB(255,255,255); /* White foreground */
m_Tree.SetCellInfo(&CellInfo);
If you are using a CFont object to create and hold the font, make sure that the font object is valid as long as the tree control uses the font. If the CFont is a temporary variable in a function, it will be destroyed as soon as the function ends. It is best placed in the tree control's parent window class so it won't go out of scope until the parent window is destroyed.
Q: 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/DLL 6.0 it is also possible to implement a sort function SFTTREE_SORTPROC_ITEM (see SortDependents). When the sort function SFTTREE_SORTPROC_ITEM is used, it is called with the indices of the two items to be compared. The function 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 the SFTTREE_SORTPROC_ITEM function is called many times for each item and retrieving item properties to build a sort key will definitely affect the overall performance.
Q: 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 sending a WM_CANCELMODE message to the tree control right before you display your popup menu. The WM_CANCELMODE message tells the tree control to stop handling the event further. |