Express Db Tree

172
Unit dxtree Controls TCustomdxTreeView TdxTreeView Page 1 of 172

Transcript of Express Db Tree

Page 1: Express Db Tree

Unit dxtree ControlsTCustomdxTreeViewTdxTreeView

Page 1 of 172

Page 2: Express Db Tree

TCustomdxTreeViewHierarchy Properties Methods Events Unitdxtree DescriptionTCustomdxTreeView is an abstract base type for tree-view components such as the TdxTreeView and TdxDBTreeView. Use TCustomdxTreeView as a base class when defining components that present information in a hierarchical structure with nodes that can expand or collapse. Drag & drop operations and new methods and features are implemented in the TCustomdxTreeView. IMPORTANT: Do not create instances of the TCustomdxTreeView. To add a tree view control with extended features (such as drag & drop, automatic node expansion during drag & drop operations, custom draw, etc.) use TdxTreeView instead. Use the TdxDBTreeView control to bind the TreeView with database information.

Page 2 of 172

Page 3: Express Db Tree

TdxTreeViewHierarchy Properties Unitdxtree DescriptionTdxTreeView is a tree-view component with full drag & drop and custom draw support. To bind your DB with tree view control use TdxDBTreeView

Page 3 of 172

Page 4: Express Db Tree

A Self-Referenced Structure To create a self-reference data structure you have to create a UNIQUE field - KEY(ID) field and a field that will be referenced to the KEY(ID) field - PARENT field. The KEY(ID) and PARENT fields must be of the same type.

Page 4 of 172

Page 5: Express Db Tree

Smart Record Loading If your DataSet has more than 1,000 records, you should use the Smart Record load feature.  To apply the smart load, follow these steps: 

1. Index (or order) the dataset by the PARENT field.2. Set trSmartRecordLoad in Options.3. Set the RootValue property to the PARENT value of your 'root' records. If you want to start with a particular record and not

display all records in the DBTreeView , you should assign to the RootValue the value of the PARENT field of this particular record and set trCanDBNavigate to False.

4. Write the OnCreateNewKeyValue event handler. When the dxDBTreeView does not load all records, the Maximum KEY field value is incorrect. You have to get the maximum KEY value to the variable on form creation and use it when the user creates new tree nodes. Otherwise on creating a new tree node you may get a key violation error.

 Smart record loading works in the following manner: On activation of a dataset, the dxDBTreeView loads records which have a PARENT value equal to RootValue (Locate the first record whose parent Value equals RootValue and then fetch and load the records when the values of the PARENT field are equal. That is why your dataset has to be sorted by the PARENT field). Then dxDBTreeView loads records if necessary - on expand nodes and when the dxDBTreeView has to retrieve the full structure of the loaded tree node.

Page 5 of 172

Page 6: Express Db Tree

Unit dxdbtree ControlsTdxDBTreeView ObjectsTdxDBTreeNodesTdxDBTreeNode

Page 6 of 172

Page 7: Express Db Tree

TdxDBTreeViewHierarchy Properties Methods EventsTdxDBTreeView object is a TreeView control that can display and edit a dataset with hierarchical structures (a self-reference dataset). Unit dxdbtree DescriptionTDBTreeView is a window that displays a hierarchical list of items related to a dataset. You can directly manipulate TreeView nodes, using drag & drop – and all changes will be reflected in the dataset. On changing the Value of a field related to the DBTreeView, both the label and parent property of the items are changed as well. You can link the TreeView to a database by specifying the data source component (TDataSource) which identifies the dataset as the value of the DBTreeView DataSource property. Set the KeyField property to a field in the dataset to be used as the key value of the items. Set the ParentField property to the field in the dataset you want to use as a parent of items. Set the ListField property to the field in the dataset you want to see as individual labels of items.

Page 7 of 172

Page 8: Express Db Tree

TdxDBTreeNodesHierarchy Properties Methods Unit dxdbtree DescriptionThe TdxDBTreeNodes object maintains a list of items (TdxDBTreeNode objects). The Items property of the data-aware tree-view control ( theTdxDBTreeView component) which is of TdxDBTreeNodes type maintains the items in the data-aware tree-view. Note: Items are created automatically.

Page 8 of 172

Page 9: Express Db Tree

TdxDBTreeNodeHierarchy Properties Methods

The TdxDBTreeNode object is an individual item of the TdxDBTreeView control. The dxDBTreeNode is related to a DB record.  Unit dxdbtree DescriptionThe dxDBTreeNode is inherited from TTreeNode. TdxDBTreeNode contains the KeyFieldValue and the ParentFieldValue defined by the KeyField Value and ParentField records of a related DataSet.

Page 9 of 172

Page 10: Express Db Tree

Unit dxdbtrel ControlsTCustomdxVTreeViewEditTCustomdxTreeViewEditTdxTreeViewEditTdxDBTreeViewEditTCustomdxLookupTreeViewTdxLookupTreeViewTdxDBLookupTreeView

Page 10 of 172

Page 11: Express Db Tree

TCustomdxVTreeViewEditHierarchy Properties Methods Events Unit dxdbtrel DescriptionTCustomdxVTreeViewEdit is an abstract base type for tree-view edit components such as TdxDBTreeViewEdit and TdxDBLookUpTreeView. Use TCustomdxVTreeViewEdit as a base class when defining a control that combines an edit box with a treeview. Do not create instances of the TCustomdxVTreeViewEdit. To add a tree-view edit control, use TdxTreeViewEdit(TdxDBTreeViewEdit) or TdxLookUpTreeView (TdxDBLookUpTreeView).

Page 11 of 172

Page 12: Express Db Tree

TCustomdxTreeViewEditHierarchy Properties Methods Unit dxdbtrel DescriptionTCustomdxTreeViewEdit is an abstract base type for tree-view edit components such as TdxTreeViewEdit and TdxDBTreeViewEdit. Use TCustomdxTreeViewEdit as a base class when defining controls that combines an edit box with a treeview. Do not create instances of the TCustomdxTreeViewEdit. To add a tree-view edit control, use the TdxTreeViewEdit or TdxDBTreeViewEdit.

Page 12 of 172

Page 13: Express Db Tree

TdxTreeViewEditHierarchy Properties Unitdxdbtrel DescriptionTTreeViewEdit component is a control that combines an edit box with a treeview. Users can select an item from the treeview.

Page 13 of 172

Page 14: Express Db Tree

TdxDBTreeViewEditHierarchy Properties Unitdxdbtrel DescriptionThe TDBTreeViewEdit component is a data-aware control that combines an edit box with a treeview. Users can edit a field by selecting an item from the drop-down tree-view.

Page 14 of 172

Page 15: Express Db Tree

TCustomdxLookupTreeViewHierarchy Properties Events Unit dxdbtrel DescriptionTCustomdxLookupTreeView is an abstract base type for the tree-view lookup components such as TdxDBLookupTreeView and TdxLookupTreeView. Use TCustomLookUpTreeView as a base class when defining a control that combines an edit box with a data-aware tree-view for the lookup purpose. Do not create instances of TCustomdxLookupTreeView. To add a data-aware tree-view lookup control, use the TdxDBLookupTreeView or TdxLookupTreeView.

Page 15 of 172

Page 16: Express Db Tree

TdxDBLookupTreeViewHierarchy Properties

TdxDBLookupTreeView component is a data-aware control that combines an edit box with a data-aware tree-view. Unit dxdbtrel DescriptionUse TdxDBLookupTreeView to provide users with a convenient data-aware drop-down tree-view for editing fields that obtain data from other datasets.

Page 16 of 172

Page 17: Express Db Tree

Unit dxtrprds ComponentsTdxDBTreePrintData

Page 17 of 172

Page 18: Express Db Tree

TdxDBTreePrintDataHierarchy Properties

The TdxDBTreePrintData component is a dataset allowing easy printing of reports using self-referenced datasets. Unit dxtrprds DescriptionUse TdxDBTreePrintData to create a report using self-referenced datasets.  TdxDBTreePrintData is directly inherited from the TdxMemData. It retrieves the Data from a self-referenced DataSet (linked with the DataSource property) and creates the records in memory, which are sorted in specific order. In addition it creates the following fields: 

Field Name Description

 

dx$haschildren Determines whether the record has children. If the 'dx$haschildren' field is True, then the record has children. If the 'dx$haschildren' field is False, then the record does not include children.

dx$Level The level of a record. The first level (level of the 'root' records) is 0.dx$recno The number of a record. The first number is 1.

Page 18 of 172

Page 19: Express Db Tree

ExpressDBTreeView Frequently Asked QuestionsQuestion 1:Why once I've assigned the ImageField & Images property, each time I move the cursor to any node, the image is replaced with the first image in the image list?

Answer: This behavior occurs because the SelectedIndex property of the DBTreeView is 0. If you want the selected index to be the same as the image index, then you have to write the following code on the onChange event handler of the DBTreeView: // Delphiprocedure TForm1.DBTreeView1Change(Sender: TObject; Node: TTreeNode);beginNode.SelectedIndex := Node.ImageIndex; end; // C++ Buildervoid __fastcall TForm1::DBTreeView1Change(TObject *Sender, TTreeNode *Node){Node->SelectedIndex = Node->ImageIndex; }  Question 2:I'm trying to use your DBTreeView component in a Delphi 3 application I am writing. It works fine until I try to enable the SmartRecordLoad option. When I enable it and try to open my table, I receive an "Invalid Variant Type Conversion" error.

Answer: You have not assigned the Root Value. DBTreeView tries to load the root records. It uses the locate method YourDataSet.Locate('YOURKEYFIELD', ROOTVALUE, []); You have to set the RootValue to the key field 'root' records value. The values of the key field 'root' records has to be equal. Question 3:I try to use smart record loading. I indexed my Table and set trSmartRecordLoad to True. When I start my application the DBTreeView doesn't display any nodes. The nodes are displayed only when I press 'Next' button in the DBNavigator. Is this a feature of the smart record loading?

Answer: No, You forgot to assign the RootValue property. Set the PARENT value of your 'root' records to this property.  Smart record loading works in the following way:  On activation of a dataset, it loads records which have the PARENT value equal to RootValue (Locate the first record that the parent Value equals to RootValue and then fetch and load the records while the value of the PARENT field doesn't change. That is why your dataset has to be sorted by the PARENT field). Then DBTreeView loads records when it is necessary – on node expansion and when the DBTreeView has to retrieve the full structure of the loaded tree node. In your particular case DBTreeView does the following: 1. Recognizes that you set smart record loading.2. Checks RootValue and decides that the PARENT value of your 'root' records is NULL.3. Tries to locate the record with the PARENT value NULL. When there is no such record, DBTreeView does not load any records. 4. When you press the 'Next' button in DBNavigator, DBTreeView checks the trCanDBNavigate and as soon as it is True (by definition it is True) loads the current record (to set it as a selected tree node) and also loads all its parent records recursively.   Question 4:We want to use a different field for a Node's text, according to the node level, how can we do this ?

Page 19 of 172

Page 20: Express Db Tree

 

Answer: 1. You have to set ReadOnly to True to disable text editing in DBTreeView.2. Write code on the OnDisplayItemText event handler to assign your Text a particular TreeNode: // Delphiprocedure TForm1.DBTreeViewSetDisplayItemText(Sender: TObject;var DisplayText: string); Vartr : TTreeNode;  begin// Get TreeNode tr := DBTreeView.DBTreeNodes.GetTreeNode(TreeQueryID.Value); if tr <> Nil then begin if tr.Level mod 2 = 1 then DisplayText := Fiedl1.Text else DisplayText := ' Fiedl2.Text; end;  end; // C++ Buildervoid __fastcall TForm1::DBTreeViewSetDisplayItemText(TObject *Sender, AnsiString &DisplayText){// Get TreeNode TTreeNode * tr = DBTreeView->DBTreeNodes->GetTreeNode(TreeQueryID->Value);  if(tr != NULL){ if((tr->Level && 1) == 1)  DisplayText = Fiedl1->Text;  else DisplayText = Fiedl2->Text;  } }  3. Add a DBEdit to a Form, bind it with your DataSet4. Write code on the OnChange event handler to change the DataField of the DBEdit to the required FieldName.  // Delphiprocedure TForm1.DBTreeViewChange(Sender: TObject; Node: TTreeNode);beginif(DBTreeView.Selected <> Nil) then begin if (DBTreeView.Selected.Level mod 2 = 1) then DBEdit.DataField := 'field1' else DBEdit.DataField := 'field2'; end; end;  // C++ Buildervoid __fastcall TForm1::DBTreeViewChange(TObject *Sender, TTreeNode *Node){if(DBTreeView->Selected != NULL){  if((DBTreeView->Selected->Level && 1) == 1)  DBEdit->DataField = "field1";  else DBEdit->DataField = "field2";  } }  Question 5:We would like to use specific fields for the state and image index values, depending on the level.

Page 20 of 172

Page 21: Express Db Tree

Answer: You have to write code on the AddNewItem event handler to change the ImageIndex property of a Tree Node.  // Delphiprocedure TForm1.DBTreeViewAddNewItem(Sender: TObject;var DBTreeNode: TdxDBTreeNode); beginif(DBTreeNode <> Nil) then begin DBTreeNode.ImageIndex := DBTreeNode.Level; DBTreeNode.StateIndex := DBTreeNode.Level;  end; end; // C++ Buildervoid __fastcall TForm1::DBTreeViewAddNewItem(TObject *Sender, TdxDBTreeNode *&DBTreeNode){if(DBTreeNode != NULL){ DBTreeNode->ImageIndex = DBTreeNode->Level;  DBTreeNode->StateIndex = DBTreeNode->Level;  } }  Question 6: I am trying to insert a child in my tree. My table structure is below, it is recursive in nature. I am using the dbTreeView component.  Table structure --------------------- ID, auto Parent, integer Name, integer lookup  Lookup for Name --------------------------- ID, auto Name, String Category, Integer Obsolete, logical (true,false)  What method do I use to insert the child since I really need to send the Name as an integer not a string? The addChild method takes a string. I need to set an integer value.

Answer:Solutions are the following:The First Option:1. Create a lookup field in the datasetThe Second Option:1. Set DBTreeView ReadOnly to True.2. Create a one-to-many relationship between your DataSets. DataSet1 is the second table (lookup table), DataSet2 is the first table (the self-referenced table) DataSet1 ->> DataSet2, BUT DataSet2 (self-reference) is the master DataSet. 3. Write code on OnDisplayItemText event handler to assign the appropriate Text  // Delphiprocedure TForm1.DBTreeViewSetDisplayItemText(Sender: TObject;var DisplayText: string); beginDisplayText := DataSet1.FindField('name').AsString end; 

Page 21 of 172

Page 22: Express Db Tree

// C++ Buildervoid __fastcall TForm1::DBTreeViewSetDisplayItemText(TObject *Sender, AnsiString &DisplayText){DisplayText = DataSet1->FindField("name")->Text;  }  Question 7:I use your DBTreeView with the SmartRecordLoad option. When I delete the root record or a record that has > 100 children, the operation takes a great amount of time. Can you decrease the time of such operation? (I use InterBase). 

Answer: No, DBTreeView can not decrease the time of delete operations when using SmartRecordLoad, but you can do it manually. When you delete the tree node (or record, it does not matter), the DBTreeView checks whether the SmartRecordLoad is active. If the SmartRecordLoad is set, DBTreeView first loads all 'child' records of the deleted record recursively and then deletes them. It works fast with ISAM databases, and you are right that it takes a lot of time if you use C/S architecture.  But if you use a C/S architecture you can easily decrease this time dramatically. Instead of using the standard DBTreeView delete operation you have to carry out such operations in the following manner: 1. Create a trigger on Delete. For example (for Interbase): REFTABLE.ID <--->> REFTABLE.PARENT Create Trigger REFTABLE$DELETE For REFTABLEAfter DeleteAsBeginDelete From REFTABLE Where PARENT = OLD.ID And ID <> OLD.ID; End Now when deleting a record all children will be deleted automatically. 2. Set the trCanDBDelete to False and obtain the KeyDown event manually: // Delphiprocedure TForm1.DBTreeViewKey1Down(Sender: TObject; var Key: Word;Shift: TShiftState); varQuery : TQuery; begin// Is it delete key and has the user selected a tree node if(Key = VK_DELETE) And (DBTreeView1.Selected <> Nil) then begin // Create a temporary query Query := TQuery.Create(self); // Set the DataBaseName Query.DataBaseName := 'MyDataBase'; // Assign the SQL property Query.SQL.Add('Delete From REFTABLE Where ID = ' +  MYDBTreeDataSet.FindField('id').AsString); // Delete the record and our trigger has to delete its children recursively Query.ExecSQL; // Free the temporary query Query.Free; // Refresh the DataSet MYDBTreeDataSet.Close; MYDBTreeDataSet.Open; end; end; 

Page 22 of 172

Page 23: Express Db Tree

 // C++ Builder//----------------------------------------------------------------- void __fastcall TForm1::DBTreeViewKeyDown(TObject *Sender, WORD &Key, TShiftState Shift){// Is it delete key and has the user selected a tree node if((Key == VK_DELETE) && (DBTreeView1->Selected != NULL)){  // Create a temporary query TQuery * Query = new TQuery(this); // Set the DatabaseName Query->DataBaseName = "MyDataBase";  // Assign the SQL property Query->SQL->Add("Delete From REFTABLE Where ID = " +   MYDBTreeDataSet->FindField("id")->Text);  // Delete the record and our trigger has to delete its children recursively Query->ExecSQL();  // Free the temporary query Query->Free();  // Refresh our DataSet MYDBTreeDataSet->Close();  MYDBTreeDataSet->Open();  } }  Question 8: The following code does not work when automatic Drag-Drop is active, but does work when it is inactive:  // Delphiprocedure TForm1.DBTreeViewMouseUp(Sender: TObject; Button: TMouseButton; Shift:TShiftState; X, Y: Integer);beginif ssShift in Shift then begin {do something} end; end; 

Answer: This is not a problem created by ExpressDBTreeView. Try to perform this operation using any other TWinControl in Delphi or CPB; for instance a ListBox control. The result will be the same. Instead of using "if ssShift in Shift then begin" condition you have to write the following code:  "if GetKeyState(VK_SHIFT) < 0 then begin". // Delphiprocedure TForm1.DBTreeViewMouseUp(Sender: TObject;Button: TMouseButton; Shift: TShiftState; X, Y: Integer); beginif GetKeyState(VK_SHIFT) < 0 then begin {do something} end; end;

Page 23 of 172

Page 24: Express Db Tree

TdxDBTreeView EventsTdxDBTreeView  OnAddNewItem OnCreateNewKeyValue OnSetDisplayItemText

Page 24 of 172

Page 25: Express Db Tree

TdxDBTreeNode MethodsTdxDBTreeNode LoadChildren

Page 25 of 172

Page 26: Express Db Tree

TdxDBTreeNodes MethodsTdxDBTreeNodes CountGetKeyFieldValueGetParentValueGetDBTreeNodeGetTreeNode

Page 26 of 172

Page 27: Express Db Tree

TdxDBTreeView MethodsTdxDBTreeView GetImageIndexFieldGetKeyFieldGetListFieldGetParentFieldGetStateIndexFieldGotoKeyFieldValueIsCustomDrawRefreshItems

Page 27 of 172

Page 28: Express Db Tree

TdxDBTreeNode PropertiesTdxDBTreeNode BkColorColorFontStyleFontNameIsCustomDraw ChildLoaded KeyFieldValue ParentFieldValue

Page 28 of 172

Page 29: Express Db Tree

TdxDBTreeNodes PropertiesTdxDBTreeNodes ItemsMaxKeyFieldValue

Page 29 of 172

Page 30: Express Db Tree

TdxDBTreeView PropertiesTdxDBTreeView  DBSelected

DBTreeNodes DataSource DisplayField ImageIndexField KeyField ListField ParentField RootValue SeparatedSt StateIndexField Options

Derived from TCustomdxTreeView DeletingConfirmationMessage Options SelectedIndex

Page 30 of 172

Page 31: Express Db Tree

TdxDBTreeNode.BkColorTdxDBTreeNodes See Also Example

Specifies the background color of tree node text. property BkColor : TColor; DescriptionSet BkColor to specify the background color of tree node text.  Note: IsCustomDraw property has to be set to True.

Page 31 of 172

Page 32: Express Db Tree

TdxDBTreeNode.ChildLoadedTdxDBTreeNodes See Also Example

Determines whether children of a dxDBTreeNode are loaded. property ChildLoaded : Boolean; DescriptionRead-Only. Use ChildLoaded to determine whether children of a DBTreeNode are loaded. If you do not use the smart record loading features, ChildLoaded is always True.

Page 32 of 172

Page 33: Express Db Tree

TdxDBTreeNode.ColorTdxDBTreeNodes See Also Example

Specifies the color of tree node text. property Color : TColor; DescriptionSet Color to specify the color of the tree node text Note: IsCustomDraw property has to be set to True.

Page 33 of 172

Page 34: Express Db Tree

TdxDBTreeNode.FontNameTdxDBTreeNodes See Also Example

Specifies the font name of tree node text. property FontName : TFontName; DescriptionSet FontName to specify the font name of tree node text.  Note: IsCustomDraw property has to be set to True.

Page 34 of 172

Page 35: Express Db Tree

TdxDBTreeNode.FontStyleTdxDBTreeNodes See Also Example

Specifies the font style of tree node text. property FontStyle : TFontStyles; DescriptionSet FontStyle to specify the font style of tree node text.  Note: IsCustomDraw property has to be set to True.

Page 35 of 172

Page 36: Express Db Tree

TdxDBTreeNode.IsCustomDrawTdxDBTreeNodes See Also Example

Specifies whether a particular tree node draws font and color properties of the TdxDBTreeView by default or by using the BkColor, Color, FontStyle and FontName properties of this TdxDBTreeNode. property IsCustomDraw : Boolean; DescriptionSet IsCustomDraw to specify whether a particular tree node draws the font and color properties of the TdxDBTreeView by default or whether it uses BkColor, Color, FontStyle and FontName properties of this TdxDBTreeNode. By default IsCustomDraw is set to False.

Page 36 of 172

Page 37: Express Db Tree

TdxDBTreeNode.KeyFieldValueTdxDBTreeNodes See Also

Determines the Value of KEY field associated with a dxDBTreeNode. property KeyFieldValue : Variant; DescriptionRun-time and Read-Only. Use KeyFieldValue to determine the Value of a KEY field associated with a dxDBTreeNode.

Page 37 of 172

Page 38: Express Db Tree

TdxDBTreeNode.LoadChildrenTdxDBTreeNodes See Also

Loads child tree nodes. procedure LoadChildren(Recurse: Boolean); DescriptionCall LoadChildren to load tree node children when using the smart record loading feature. Set the Recurse parameter to True to load all tree node records.

Page 38 of 172

Page 39: Express Db Tree

TdxDBTreeNode.ParentFieldValueTdxDBTreeNodes See Also

Determines the Value of a PARENT field associated with a DBTreeNode. property ParentFieldValue: Variant; DescriptionRun-time and Read-Only. Use ParentFieldValue to determine the Value of a ParentFieldValue field associated with a dxDBTreeNode.

Page 39 of 172

Page 40: Express Db Tree

TdxDBTreeNodes.CountTdxDBTreeNodes

Determines the number of DBTreeNode items in an object. function Count : Integer; DescriptionCall Count to determine the number of DBTreeNode items in an object.

Page 40 of 172

Page 41: Express Db Tree

TdxDBTreeNodes.GetDBTreeNodeTdxDBTreeNodes

Returns DBTreeNode items by its KeyValue. function GetDBTreeNode(Value : Variant) : TDBTreeNode; DescriptionCall GetDBTreeNode to return DBTreeNode items by its KeyValue.

Page 41 of 172

Page 42: Express Db Tree

TdxDBTreeNodes.GetKeyFieldValueTdxDBTreeNodes See Also

Returns the Value of the KeyField field associated with a dxDBTreeNode. function GetKeyFieldValue(Value : TTreeNode) : Variant; DescriptionCall GetKeyFieldValue to return the KeyField field Value associated with a TreeNode parameter Value.

Page 42 of 172

Page 43: Express Db Tree

TdxDBTreeNodes.GetParentValueTdxDBTreeNodes See Also

Returns the Value of the ParentField field associated with a dxDBTreeNode. function GetParentValue(Value : TTreeNode) : Variant; DescriptionCall GetParentValue to return the Value of the ParentField field associated with a TreeNode parameter Value.

Page 43 of 172

Page 44: Express Db Tree

TdxDBTreeNodes.GetTreeNodeTdxDBTreeNodes

Returns the TreeNode items by its KeyValue. function GetTreeNode(Value : Variant) : TTreeNode; DescriptionCall GetTreeNode to return TreeNode items by its KeyValue.

Page 44 of 172

Page 45: Express Db Tree

TdxDBTreeNodes.ItemsTdxDBTreeNodes See Also

An index of the DBdxTreeNodes in the TdxDBTreeNodes. property Items[Index: Integer]: TDBTreeNode; DescriptionThe Items property contains individual items that appear in the dbtree view control. Individual nodes in the TdxDBTreeView are the TdxDBTreeNode objects. These items can be accessed by means of the Items property along with the item's index into the dbtree view. For example, to access the first db item in a DBTreeView, you could use the following code: MyDBTreeNode := DBTreeView1.DBNodes[0];

Page 45 of 172

Page 46: Express Db Tree

TdxDBTreeNodes.MaxKeyFieldValueTdxDBTreeNodes See Also Example

Determines the greatest value of the dxDBTreeNode Key value. property MaxKeyFieldValue : Variant; DescriptionUse MaxKeyFieldValue to determine the greatest value of the DBTreeNode Key value.  Note: When using smart record loading, this value will be incorrect.

Page 46 of 172

Page 47: Express Db Tree

TdxDBTreeView.DataSourceTdxDBTreeView See Also

Identifies a link to the dataset where a data-aware tree view locates its data. property DataSource: TDataSource; DescriptionSet DataSource to the TDataSource object that links to a dataset where the data-aware tree-view should fetch its data. The linked dataset must have a self-reference structure.

Page 47 of 172

Page 48: Express Db Tree

TdxDBTreeView.DBSelectedTdxDBTreeView See Also

Returns the DB item in a selected DBtree view. property DBSelected : TdxDBTreeNode; DescriptionRun-time and read only.  Use DBSelected to retrieve the selected DB item in a data-aware tree-view. This is included only for compatibility with RSD DBTreeView. The TdxDBTreeNode is inherited from the TTreeNode: MyTreeView.DBSelected = TdxDBTreeNode(MyTreeView.Selected);

Page 48 of 172

Page 49: Express Db Tree

TdxDBTreeView.DBTreeNodesTdxDBTreeView

DBTreeNodes is an indexed array of all TDBTreeNodes in a data-aware tree-view. property DBTreeNodes : TdxDBTreeNodes; DescriptionUse the DBTreeNodes to gain direct access to a particular dxDBTreeNode in a data-aware tree-view. Specify which DB item to access by means of Index, where an Index of 0 specifies the first item, an Index of 1 specifies the second item, etc. Each item is a TdxDBTreeNode object. The items are created automatically. This is included only for compatibility with RSD DBTreeView. The TdxDBTreeNode is inherited from the TTreeNode.

Page 49 of 172

Page 50: Express Db Tree

TdxDBTreeView.DisplayFieldTdxDBTreeView See Also

Identifies the field (or fields) from which a data-aware tree-view displays data. property DisplayField : String; DescriptionSet the DisplayField property to a field name or multiple field names (separated by semicolons) whose values you would like to display for a TreeNode’s Text. You have to use this property if you wish to display more than one field or a field different from the ListField.

Page 50 of 172

Page 51: Express Db Tree

TdxDBTreeView.GetImageIndexFieldTdxDBTreeView See Also

Returns the ImageIndexField. function GetImageIndexField : TField; DescriptionCall GetImageIndexField to return the ImageIndexField if a linked DataSet is Active and the ImageIndexField property has been assigned, otherwise returns Nil.

Page 51 of 172

Page 52: Express Db Tree

TdxDBTreeView.GetKeyFieldTdxDBTreeView See Also

Returns the KeyField. function GetKeyField : TField; DescriptionCall GetKeyField to return the KeyField if a linked DataSet is Active and the KeyField property has been assigned, otherwise returns Nil.

Page 52 of 172

Page 53: Express Db Tree

TdxDBTreeView.GetListFieldTdxDBTreeView See Also

Returns the ListField. function GetListField : TField; DescriptionCall GetListField to return the ListField if a linked DataSet is Active and the ListField property has been assigned, otherwise returns Nil.

Page 53 of 172

Page 54: Express Db Tree

TdxDBTreeView.GetParentFieldTdxDBTreeView See Also

Returns the ParentField. function GetParentField: TField; DescriptionCall GetParentField to return the ParentField if a linked DataSet is Active and the ParentField property has been assigned, otherwise returns Nil.

Page 54 of 172

Page 55: Express Db Tree

TdxDBTreeView.GetStateIndexFieldTdxDBTreeView See Also

Returns the StateIndexField function GetStateIndexField : TField; DescriptionCall GetStateIndexField to return the StateIndexField if a linked DataSet is Active and the StateIndexField property has been assigned, otherwise returns Nil.

Page 55 of 172

Page 56: Express Db Tree

TdxDBTreeView.GotoKeyFieldValueTdxDBTreeView See Also

Allows you to move to a particular DBTreeNode Item. procedure GotoKeyFieldValue(Value : Variant); DescriptionCall GotoKeyFieldValue to navigate to a dxDBTreeNode Item whose KeyValue is equal to Value.

Page 56 of 172

Page 57: Express Db Tree

TdxDBTreeView.ImageIndexFieldTdxDBTreeView See Also

Specifies the field used by a data-aware tree-view control to set the ImageIndex property of a TreeNode.  property ImageIndexField: String; DescriptionSet ImageIndexField to specify the field used by a data-aware tree-view control to set the ImageIndex property of the TreeNode. The dataset of the field is specified by the data source component (TDataSource). ImageIndexField must be an integer field.

Page 57 of 172

Page 58: Express Db Tree

TdxDBTreeView.IsCustomDrawTdxDBTreeView See Also

Determines whether custom draw is used. function IsCustomDraw : Boolean; override; DescriptionCall IsCustomDraw to determine whether custom draw is used. It returns True if custom draw is used and False if not. Custom draw is used if you write code within the OnCustomDraw event handler or if at least one IsCustomDraw property of the DBTreeNode object is set to True.

Page 58 of 172

Page 59: Express Db Tree

TdxDBTreeView.KeyFieldTdxDBTreeView See Also

Identifies the KEY field of a self-reference dataset. property KeyField: string; DescriptionSet the KeyField property to a KEY field in a self-reference dataset. The dataset is specified by a data source component (TDataSource).

Page 59 of 172

Page 60: Express Db Tree

TdxDBTreeView.ListFieldTdxDBTreeView See Also

Identifies the field which displays item labels for a data-aware tree-view control. property ListField: string; DescriptionSet the ListField property to identify the field which displays the item labels for a data-aware tree-view control. The dataset of the field is specified by a data source component (TDataSource).

Page 60 of 172

Page 61: Express Db Tree

TdxDBTreeView.OnAddNewItemTdxDBTreeView Example

Occurs when dxDBTreeView must add a new item. TAddNewDBTreeNodeEvent= procedure(Sender: TObject; var DBTreeNode: TdxDBTreeNode) of Object;

property OnAddNewItem : TAddNewDBTreeNodeEvent; DescriptionUse OnAddNewItem event to perform particular operations when adding new items, for example to assign an ImageIndex, SelectedIndex and StateIndex property of a TreeNode item.

Page 61 of 172

Page 62: Express Db Tree

TdxDBTreeView.OnCreateNewKeyValueTdxDBTreeView See Also Example

Occurs when a data-aware tree-view has already inserted the tree node and tries to insert a new record in the dataset. TCreateNewKeyValue = procedure(Sender: TObject; var NewKeyValue: Variant) of Object;

property OnCreateNewKeyValue : TCreateNewKeyValue; DescriptionWrite an OnCreateNewKeyValue event handler to assign a new Key Value to the newly inserted tree node. The NewKeyValue is the greatest value in the Key field plus 1 for integer and float fields. This gives a programmer the opportunity to change the NewKeyValue (the key value for new data record). It is especially useful if the key field is not integer and is not float.  Note: You must assign this event if you use SmartLoad. If dxDBTreeView does not load all records, it has an incorrect maximum value of the key field.

Page 62 of 172

Page 63: Express Db Tree

TdxDBTreeView.OnSetDisplayItemTextTdxDBTreeView See Also Example

Occurs when a data-aware tree-view has to display an item. TSetDisplayItemText = procedure(Sender: TObject; var DisplayText: String) of Object;

property OnSetDisplayItemText : TSetDisplayItemText; DescriptionWrite an OnSetDisplayItemText event handler to assign tree node Text a specific value. DisplayText is the text to be displayed.

Page 63 of 172

Page 64: Express Db Tree

TdxDBTreeView.OptionsTdxDBTreeView See Also

Specifies various behavioral properties of the data-aware tree-view. TdxDBTreeViewOption = (trDBCanDelete, trDBConfirmDelete, trCanDBNavigate, trSmartRecordLoad, trSmartRecordCopy, trCheckHasChildren);TdxDBTreeViewOptions = set of TdxDBTreeViewOption;

property Options : TdxDBTreeViewOptions; DescriptionSet Options to include the desired properties for the data-aware tree-view. Options is a set drawn from the following values:  

Value Meaning

 

trDBCanDelete Deletes the selected tree node and its structure, when the user presses the Delete key.

trDBConfirmDelete A message box appears, asking for confirmation, when a user presses the Delete key to delete a node in the DBTreeView. The trDBCanDelete must also be set.

trCanDBNavigate On changing the DB cursor in a linked DataSet, the selected tree node is also changed.

trSmartRecordLoad DBTreeView uses the smart record loading feature.

trSmartRecordCopy On drag & drop events, copies the associated data in the dataset. By default the Key, Parent and Name fields are the only items copied.

trCheckHasChildren Checks whether a tree node includes children. By default this options is inactive and dxDBTreeView does not check whether a node has children when using the smart record load feature. The resultant effect is that the HasChildren property of all nodes equals True (the plus symbol is shown within the tree). To check whether nodes have children (dxDBTreeView tries to find any child records) set this option. If you do not use the smart record load feature, dxDBTreeView ignores this option.

Page 64 of 172

Page 65: Express Db Tree

TdxDBTreeView.ParentFieldTdxDBTreeView See Also

Identifies the PARENT field of a self-reference dataset. property ParentField: string; DescriptionSet the ParentField property to the PARENT field of a self-reference dataset. The dataset of the field is specified by a data source component (TDataSource).

Page 65 of 172

Page 66: Express Db Tree

TdxDBTreeView.RefreshItemsTdxDBTreeView

Refreshes the items of a data-aware tree-view. procedure RefreshItems; DescriptionCall RefreshItems to refresh the items of a data-aware tree-view. You rarely need to call this procedure directly.

Page 66 of 172

Page 67: Express Db Tree

TdxDBTreeView.RootValueTdxDBTreeView See Also

Determines the PARENT value of your 'root' records. property RootValue : String; DescriptionSet the RootValue property to the PARENT value of your 'root' records. This is a critical property when using smart record loading. When a dataset is activated, DBTreeView loads the records which have a PARENT value equal to RootValue (locate the first record which the parent Value equals to RootValue and then fetch and load the records when the values of their PARENT field are equal. That is why your dataset has to be sorted by the PARENT field).

Page 67 of 172

Page 68: Express Db Tree

TdxDBTreeView.SeparatedStTdxDBTreeView See Also

Determines the string which is used as a separator between values of different fields in a Tree Node’s Text, once the DisplayField property is assigned. property SeparatedSt : string; DescriptionSet SeparatedSt to determine the string which is used as separators between values of different fields in a Tree Node’s Text, once the DisplayField property is assigned. The default value is ' - '.

Page 68 of 172

Page 69: Express Db Tree

TdxDBTreeView.StateIndexFieldTdxDBTreeView See Also

Specifies the field which is used by a data-aware tree-view control to set the StateIndex property of a TreeNode.  property StateIndexField: String; DescriptionSet StateIndexField to specify the field which is used by a data-aware tree-view control to set the StateIndex property of a TreeNode. The dataset is specified by a data source component (TDataSource). StateIndexField must be an integer field.

Page 69 of 172

Page 70: Express Db Tree

TCustomdxLookupTreeView EventsTCustomdxLookupTreeView  OnAddNewItem OnSetDisplayItemText

Page 70 of 172

Page 71: Express Db Tree

TCustomdxVTreeViewEdit EventsTCustomdxVTreeView Edit  OnCloseUp OnCustomDraw OnDropDown OnGetSelectedIndex OnGetImageIndex

Page 71 of 172

Page 72: Express Db Tree

TCustomdxTreeViewEdit MethodsTCustomdxTreeView Edit GetTreeNodeByText

Page 72 of 172

Page 73: Express Db Tree

TCustomdxVTreeViewEdit MethodsTCustomdxVTreeView Edit CloseUpDropDown

Page 73 of 172

Page 74: Express Db Tree

TCustomdxLookupTreeView PropertiesTCustomdxLookupTreeView 

In TCustomdxLookupTreeView AssignField DisplayField ImageIndexField ListSource KeyField ListField Options ParentField RootValue StateIndexField

Derived from TCustomdxVTreeViewEdit DividedChar TextStyle

Page 74 of 172

Page 75: Express Db Tree

TCustomdxTreeViewEdit propertiesTCustomdxTreeView Edit 

In TCustomdxTreeViewEdit Items

Derived from TCustomdxVTreeViewEdit DividedChar TextStyle

Page 75 of 172

Page 76: Express Db Tree

TCustomdxVTreeViewEdit PropertiesTCustomdxVTreeView Edit  DividedChar TextStyle

Selected CanSelectParents DropDownRows DropDownWidth Text TreeViewColor TreeViewCursor TreeViewFont TreeViewHint TreeViewImages TreeViewIndent TreeViewPopupMenu TreeViewReadOnly TreeViewShowButtons TreeViewShowHint TreeViewShowLines TreeViewShowRoot TreeViewSortType TreeViewStateImages

Page 76 of 172

Page 77: Express Db Tree

TdxDBLookupTreeView propertiesTdxDBLookupTreeView Field DataField DataSource ReadOnly

Page 77 of 172

Page 78: Express Db Tree

TdxDBTreeViewEdit PropertiesTdxDBTreeView Edit Field DataField DataSource ReadOnly

Page 78 of 172

Page 79: Express Db Tree

TdxLookupTreeView propertiesTdxLookupTreeView  Alignment

Page 79 of 172

Page 80: Express Db Tree

TdxTreeViewEdit propertiesTdxTreeView Edit  Alignment

Page 80 of 172

Page 81: Express Db Tree

TCustomdxLookupTreeView.AssignFieldTCustomdxLookupTreeView See Also

Identifies the field in a ListSource dataset that matches the value of a DataField. property AssignField: String; DescriptionUse AssignField to link a ListSource of the lookup TreeView to a DataSource. Though the name of the field specified as the AssingField must not to be the same as the name of the field specified as the DataField, the two fields must have the same values. Generally, the KeyField and AssignField in the lookup TreeView are the same, in which case you can leave the AssignField empty.

Page 81 of 172

Page 82: Express Db Tree

TCustomdxLookupTreeView.DisplayFieldTCustomdxLookupTreeView See Also

Specifies the DisplayField property of a drop-down data-aware tree view control. property DisplayField: String; DescriptionUse DisplayField to specify the DisplayField property of a drop-down data-aware tree view control.

Page 82 of 172

Page 83: Express Db Tree

TCustomdxLookupTreeView.ImageIndexFieldTCustomdxLookupTreeView See Also

Specifies the field, which is used by a data-aware tree-view control to set the ImageIndex property of a TreeNode.  property ImageIndexField: String; DescriptionSet ImageIndexField to specify the field, which is used by the data-aware tree-view control to set the ImageIndex property of a TreeNode. The dataset is specified by a data source component (TDataSource). ImageIndexField must be an integer field.

Page 83 of 172

Page 84: Express Db Tree

TCustomdxLookupTreeView.KeyFieldTCustomdxLookupTreeView See Also

Specifies the KeyField of a drop-down tree-view. property KeyField: String; DescriptionUse KeyField to specify the KeyField of a drop-down tree-view. If the AssignField is empty, the lookup tree view uses the KeyField to link the ListSource to the DataSource.

Page 84 of 172

Page 85: Express Db Tree

TCustomdxLookupTreeView.ListFieldTCustomdxLookupTreeView See Also

Specifies the ListField of a drop-down tree-view. property ListField: String; DescriptionUse ListField to specify the ListField of a drop-down tree-view.

Page 85 of 172

Page 86: Express Db Tree

TCustomdxLookupTreeView.ListSourceTCustomdxLookupTreeView See Also

Specifies the DataSource of a drop-down tree-view. property ListSource: TDataSource; DescriptionUse ListSource to specify the DataSource of a drop-down tree-view.

Page 86 of 172

Page 87: Express Db Tree

TCustomdxLookupTreeView.OnAddNewItemTCustomdxLookupTreeView See Also

Occurs when a data-aware drop-down tree-view must add a new item. TAddNewDBTreeNodeEvent= procedure(Sender: TObject; var DBTreeNode: TdxDBTreeNode) of Object;property OnAddNewItem : TAddNewDBTreeNodeEvent; DescriptionWrite an OnAddNewItem event handler to perform specific operations when adding a new item to the data-aware drop-down tree-view. Use it, for example, to assign the ImageIndex, SelectedIndex and StateIndex property of a tree node item.

Page 87 of 172

Page 88: Express Db Tree

TCustomdxLookupTreeView.OnSetDisplayItemTextTCustomdxLookupTreeView See Also

Specifies the OnSetDisplayItemText of a drop-down tree-view. TSetDisplayItemText = procedure(Sender: TObject; var DisplayText: String) of Object;property OnSetDisplayItemText : TSetDisplayItemText; DescriptionUse OnSetDisplayItemText to specify the OnSetDisplayItemText of a drop-down tree-view.

Page 88 of 172

Page 89: Express Db Tree

TCustomdxLookupTreeView.OptionsTCustomdxLookupTreeView

Specifies the Options of a drop-down tree-view. property Options: TdxDBTreeViewOptions; DescriptionUse Options to specify the Options of a drop-down tree-view.

Page 89 of 172

Page 90: Express Db Tree

TCustomdxLookupTreeView.ParentFieldTCustomdxLookupTreeView See Also

Specifies the Options of a drop-down tree-view. property ParentField: String; DescriptionUse ParentField to specify the ParentField of a drop-down tree-view.

Page 90 of 172

Page 91: Express Db Tree

TCustomdxLookupTreeView.RootValueTCustomdxLookupTreeView See Also

Specifies the Options of a drop-down tree-view. property RootValue: String; DescriptionUse RootValue to specify the RootValue of a drop-down tree-view.

Page 91 of 172

Page 92: Express Db Tree

TCustomdxLookupTreeView.StateIndexFieldTCustomdxLookupTreeView See Also

Specifies the field used by a data-aware tree-view control to set the StateIndex property of a tree node.  property StateIndexField: String; DescriptionSet StateIndexField to specify the field used by a data-aware tree-view control to set the StateIndex property of a tree node. The dataset is specified by a data source component (TDataSource). StateIndexField must be an integer field.

Page 92 of 172

Page 93: Express Db Tree

TCustomdxTreeViewEdit.GetTreeNodeByTextTCustomdxTreeView Edit

Returns the tree node of a drop-down tree-view control by its text. function GetTreeNodeByText(ParentTreeNode : TTreeNode; Text : String; flag : Boolean) : TTreeNode; DescriptionCall GetTreeNodeByText to get the tree node of a drop-down tree-view control by its text. The ParentTreeNode parameter is a tree node from which the searching begins.  To search all children of the ParentTreeNode recursively, set the flag parameter to True. To search the entire tree view, use nil as a ParentTreeNode parameter.

Page 93 of 172

Page 94: Express Db Tree

TCustomdxTreeViewEdit.ItemsTCustomdxTreeView Edit

Items is the items of a drop-down tree-view control. property Items : TTreeNodes; DescriptionThe Items array property allows you to access a specific pointer kept in the Items property of a drop-down tree-view control.

Page 94 of 172

Page 95: Express Db Tree

TCustomdxVTreeViewEdit.CanSelectParentsTCustomdxVTreeView Edit

Specifies whether a user may choose a tree node with children from the drop-down tree-view. property CanSelectParents : Boolean; DescriptionUse CanSelectParents to specify whether a user may choose a tree node with children from the popup tree-view. If CanSelectParents is True, then the user may choose the tree node, with children. If CanSelectParents is False, then he or she cannot.

Page 95 of 172

Page 96: Express Db Tree

TCustomdxVTreeViewEdit.CloseUpTCustomdxVTreeView Edit See Also

Closes a drop-down tree-view control. procedure CloseUp(Accept: Boolean); virtual; DescriptionCall CloseUp to programmatically close a drop-down tree-view control. The Accept parameter determines whether to modify the field value with the value that corresponds to the selected node in a drop-down tree-view control.

Page 96 of 172

Page 97: Express Db Tree

TCustomdxVTreeViewEdit.DividedCharTCustomdxVTreeView Edit See Also

Specifies the char that separates the Text property. property DividedChar : Char; DescriptionUse DividedChar to specify the char that separates the Text property. For example if the DividedChar is '-', the selected item is 'San Jose' and its parents are 'CA' and 'US', the Text would be the following: 'US-CA-San Jose'.

Page 97 of 172

Page 98: Express Db Tree

TCustomdxVTreeViewEdit.DropDownTCustomdxVTreeView Edit See Also

Opens a drop-down tree-view control so that a user can choose a tree node. procedure DropDown; virtual; DescriptionCall DropDown to programmatically open a drop-down tree-view control. Before a tree-view control is displayed, the OnDropDown event is generated.

Page 98 of 172

Page 99: Express Db Tree

TCustomdxVTreeViewEdit.DropDownRowsTCustomdxVTreeView Edit See Also

Specifies the maximum number of tree nodes displayed at one time within the drop-down tree-view. property DropDownRows: Integer; DescriptionSet DropDownRows to specify the maximum number of tree nodes displayed within the drop-down tree-view.

Page 99 of 172

Page 100: Express Db Tree

TCustomdxVTreeViewEdit.DropDownWidthTCustomdxVTreeView Edit See AlsoDetermines the width of a drop-down treeview property DropDownWidht : Boolean; DescriptionUse DropDownWidth to set the width of the drop-down treeview by default. If the DropDownWidht is 0, then the width of the drop-down treeview will be the same as of the treeview editor.  Note: A user can change the DropDownWidth property at run-time by re-sizing the drop-down tree-view window.

Page 100 of 172

Page 101: Express Db Tree

TCustomdxVTreeViewEdit.OnCloseUpTCustomdxVTreeView Edit See Also

Occurs immediately after a drop-down tree-view control is closed. TdxTreeViewCloseUp = procedure (Sender : TObject; Accept : Boolean) of object;property OnCloseUp: TdxTreeViewCloseUp; DescriptionWrite an OnCloseUp event handler to respond when a drop-down tree-view control is closed. When the drop-down tree-view control is closed, the Text of a selected tree node (or the value that corresponds to the selected node for lookup controls) is assigned to the field. The drop-down tree-view control can be closed by a user or by calling the CloseUp method.

Page 101 of 172

Page 102: Express Db Tree

TCustomdxVTreeViewEdit.OnCustomDrawTCustomdxVTreeView Edit See Also

Occurs when a drop-down tree-view control paints a particular tree node in using the custom draw services and the Win32 API requests the font and color for this particular tree node. TTreeViewCustomDraw = procedure(Sender : TObject; TreeNode : TTreeNode; Var AFont : TFont; Var AColor, ABkColor : TColor) of object;

property OnCustomDraw: TTreeViewCustomDraw; DescriptionUse the OnCustomDraw event handler to implement custom draw services. The OnCustomDraw handler can set the font, color and background color of text for a particular tree node of a drop-down tree-view control.

Page 102 of 172

Page 103: Express Db Tree

TCustomdxVTreeViewEdit.OnDropDownTCustomdxVTreeView Edit See Also

Occurs immediately before a drop-down tree-view control is opened. property OnDropDown: TNotifyEvent; DescriptionWrite an OnDropDown event handler to perform specific actions before a drop-down tree-view control is displayed to the user. The drop-down tree-view control can be opened by a user or by calling the DropDown method.

Page 103 of 172

Page 104: Express Db Tree

TCustomdxVTreeViewEdit.OnGetImageIndexTCustomdxVTreeView Edit

Occurs when a tree view looks up the ImageIndex of a node of a drop-down tree view.  type TTVExpandedEvent = procedure(Sender: TObject; Node: TTreeNode) of object;property OnGetImageIndex: TTVExpandedEvent; DescriptionWrite an OnGetImageIndex event handler to change the image index for a particular node of a drop-down tree view before it is drawn. For example, the bitmap of a node can be changed to indicate a different state for the node.

Page 104 of 172

Page 105: Express Db Tree

TCustomdxVTreeViewEdit.OnGetSelectedIndexTCustomdxVTreeView Edit

Occurs when a drop-down tree view looks up the SelectedIndex of a node of a drop-down tree view. type TTVExpandedEvent = procedure(Sender: TObject; Node: TTreeNode) of object;property OnGetSelectedIndex: TTVExpandedEvent; DescriptionWrite an OnGetSelectedIndex event handler to change the selected image index of a node of a drop-down tree view before it is drawn.

Page 105 of 172

Page 106: Express Db Tree

TCustomdxVTreeViewEdit.SelectedTCustomdxVTreeView Edit

Determines the selected tree node in a drop-down tree-view control. property Selected : TTreeNode; DescriptionUse Selected to determine the selected tree node in a drop-down tree-view control.

Page 106 of 172

Page 107: Express Db Tree

TCustomdxVTreeViewEdit.TextTCustomdxVTreeView Edit See Also

Contains the text associated with the control. property Text : String; DescriptionText equals the label of the selected item if the TextStyle is tvtsShort and to the label of the selected item and all labels of its parent items separated by the DividedChar property if the TextStyle is tvtsFull.

Page 107 of 172

Page 108: Express Db Tree

TCustomdxVTreeViewEdit.TextStyleTCustomdxVTreeView Edit See Also

Specifies the method of displaying TCustomAutoTreeViewEdit Text. TTVTextStyle = (tvtsShort, tvtsFull);property TextStyle : TTVTextStyle; DescriptionUse TextStyle to specify the method of displaying TCustomdxVTreeViewEdit Text. The Text equals the label of the selected item if the TextStyle is tvtsShort and to the label of the selected item and all labels of its parent items separated by the DividedChar property if the TextStyle is tvtsFull.

Page 108 of 172

Page 109: Express Db Tree

TCustomdxVTreeViewEdit.TreeViewColorTCustomdxVTreeView Edit See Also

Specifies the color of a drop-down tree-view control. property TreeViewColor : TColor; DescriptionUse TreeViewColor to specify the color of a drop-down tree-view control.

Page 109 of 172

Page 110: Express Db Tree

TCustomdxVTreeViewEdit.TreeViewCursorTCustomdxVTreeView Edit See Also

Specifies the cursor of a drop-down tree-view control. property TreeViewCursor : TCursor; DescriptionUse TreeViewCursor to specify the cursor of a drop-down tree-view control.

Page 110 of 172

Page 111: Express Db Tree

TCustomdxVTreeViewEdit.TreeViewFontTCustomdxVTreeView Edit See Also

Specifies the font of a drop-down tree-view control. property TreeViewFont : TFont; DescriptionUse TreeViewFont to specify the font of a drop-down tree-view control.

Page 111 of 172

Page 112: Express Db Tree

TCustomdxVTreeViewEdit.TreeViewHintTCustomdxVTreeView Edit See Also

Specifies the hint of a drop-down tree-view control. property TreeViewHint : String; DescriptionUse TreeViewHint to specify the hint of a drop-down tree-view control.

Page 112 of 172

Page 113: Express Db Tree

TCustomdxVTreeViewEdit.TreeViewImagesTCustomdxVTreeView Edit See Also

Specifies the images of a drop-down tree-view control. property TreeViewImages : TImageList; DescriptionUse TreeViewImages to specify the images of a drop-down tree-view control.

Page 113 of 172

Page 114: Express Db Tree

TCustomdxVTreeViewEdit.TreeViewIndentTCustomdxVTreeView Edit See Also

Specifies the indentation of a drop-down tree-view control. property TreeViewIndent : Integer; DescriptionUse TreeViewIndent to specify the indentation of a drop-down tree-view control.

Page 114 of 172

Page 115: Express Db Tree

TCustomdxVTreeViewEdit.TreeViewPopupMenuTCustomdxVTreeView Edit See Also

TreeViewPopupMenu specifies the popup menu of a drop-down tree-view control. property TreeViewPopupMenu : TPopupMenu; DescriptionUse TreeViewPopupMenu to specify the popup menu of a drop-down tree-view control.

Page 115 of 172

Page 116: Express Db Tree

TCustomdxVTreeViewEdit.TreeViewReadOnlyTCustomdxVTreeView Edit See Also

Specifies if ReadOnly determines whether the user can edit the node of a drop-down tree-view control. property TreeViewReadOnly : Boolean; DescriptionUse TreeViewReadOnly to specify if ReadOnly determines whether the user can edit the node of a drop-down tree-view control.

Page 116 of 172

Page 117: Express Db Tree

TCustomdxVTreeViewEdit.TreeViewShowButtonsTCustomdxVTreeView Edit See Also

Specifies whether to display plus (+) and minus (-) buttons to the left of each parent item of a drop-down tree-view control. property TreeViewShowButtons: Boolean; DescriptionIf TreeViewShowButtons is True, a button will appear to the left of each parent item of a drop-down tree-view control. A user can click the button to expand or collapse the child items as an alternative to double-clicking the parent item.

Page 117 of 172

Page 118: Express Db Tree

TCustomdxVTreeViewEdit.TreeViewShowHintTCustomdxVTreeView Edit See Also

Determines the ShowHint property of a drop-down tree-view control. property TreeViewShowHint: Boolean; DescriptionUse TreeViewImages to determine the ShowHint property of a drop-down tree-view control.

Page 118 of 172

Page 119: Express Db Tree

TCustomdxVTreeViewEdit.TreeViewShowLinesTCustomdxVTreeView Edit See Also

Specifies whether lines that link child nodes of a drop-down tree-view control to their corresponding parent nodes are displayed. property TreeViewShowLines: Boolean; DescriptionIf TreeViewShowLines is True, the lines linking child nodes of a drop-down tree-view control to their parent nodes are displayed. The nodes at the root of the hierarchy are not automatically linked. To link nodes at the root, the TreeViewShowRoot property must also be set to True.

Page 119 of 172

Page 120: Express Db Tree

TCustomdxVTreeViewEdit.TreeViewShowRootTCustomdxVTreeView Edit See Also

Specifies whether lines connecting the top-level nodes of a drop-down tree-view control are displayed.  property TreeViewShowRoot: Boolean; DescriptionTo display the lines in a drop-down tree-view control connecting the top-level nodes to a single root, set the TreeViewShowRoot and TreeViewShowLines properties of the tree view to True.

Page 120 of 172

Page 121: Express Db Tree

TCustomdxVTreeViewEdit.TreeViewSortTypeTCustomdxVTreeView Edit See Also

Determines the sort type of a drop-down tree-view control. property TreeViewSortType : TSortType; DescriptionUse TreeViewSortType to determine the sort type of a drop-down tree-view control.

Page 121 of 172

Page 122: Express Db Tree

TCustomdxVTreeViewEdit.TreeViewStateImagesTCustomdxVTreeView Edit See Also

Determines the state images of a drop-down tree-view control. property property TreeViewStateImages : TImageList; DescriptionUse TreeViewStateImages to determine the state images of a drop-down tree-view control.

Page 122 of 172

Page 123: Express Db Tree

TdxDBLookupTreeView.DataFieldTdxDBLookupTreeView See Also

Specifies the field from which TdxDBTreeViewEdit displays data. property DataField: string; DescriptionUse DataField to bind TdxDBTreeViewEdit to a field in a dataset. To fully specify a database field, both the dataset and the field within that dataset must be defined. The DataSource property of the edit box control specifies the dataset that contains the DataField.

Page 123 of 172

Page 124: Express Db Tree

TdxDBLookupTreeView.DataSourceTdxDBLookupTreeView See Also

Links the TdxDBLookupTreeView to a dataset which contains the field it represents. property DataSource: TDataSource; DescriptionUse DataSource to link TdxDBLookupTreeView to a dataset in which the data is found. To fully specify a database field for the edit control, both the dataset and a field within that dataset must be defined. Use the DataField property to specify a particular field within the dataset.

Page 124 of 172

Page 125: Express Db Tree

TdxDBLookupTreeView.FieldTdxDBLookupTreeView See Also

Specifies the TField object for a database field represented by TdxDBLookupTreeView. property Field: TField; DescriptionRead Field to get direct access to the contents and properties of a database. Use Field to change the contents of the database field programmatically.

Page 125 of 172

Page 126: Express Db Tree

TdxDBLookupTreeView.ReadOnlyTdxDBLookupTreeView

Determines whether a user can change the value of a field. property ReadOnly: Boolean; DescriptionSet ReadOnly to specify whether TdxDBLookupTreeView is used for display purposes only. If ReadOnly is True, TdxDBLookupTreeView can only be used for display purposes. If ReadOnly is False, the user can use the TdxDBLookupTreeView to edit a field's value.

Page 126 of 172

Page 127: Express Db Tree

TdxDBTreeViewEdit.DataFieldTdxDBTreeView Edit See Also

Specifies the field from which the TdxDBTreeViewEdit displays its data. property DataField: string; DescriptionUse DataField to bind the TdxDBTreeViewEdit to a field in a dataset. To fully specify a database field, both the dataset and the field within that dataset must be defined. The DataSource property of an edit box control specifies the dataset that contains the DataField.

Page 127 of 172

Page 128: Express Db Tree

TdxDBTreeViewEdit.DataSourceTdxDBTreeView Edit See Also

DataSource links the TdxDBTreeViewEdit to a dataset. property DataSource: TDataSource; DescriptionUse DataSource to link the TdxDBTreeViewEdit to a dataset from where data is obtained. To fully specify a database field for an edit control, both the dataset and a field within that dataset must be defined. Use the DataField property to specify a particular field within the dataset.

Page 128 of 172

Page 129: Express Db Tree

TdxDBTreeViewEdit.FieldTdxDBTreeView Edit See Also

Specifies the TField object for a database field represented by TdxDBTreeViewEdit. property Field: TField; DescriptionRead Field to get direct access to the contents and properties of a database. Use Field to change the contents of a database field programmatically.

Page 129 of 172

Page 130: Express Db Tree

TdxDBTreeViewEdit.ReadOnlyTdxDBTreeView Edit See Also

Determines if a user can change the value of a field. property ReadOnly: Boolean; DescriptionSet ReadOnly to specify whether TdxDBTreeViewEdit should be used for display purposes only. If ReadOnly is True, TdxDBTreeViewEdit can only be used to display the value of a field on the current record. If ReadOnly is False, the user can use TdxDBTreeViewEdit to edit the field's value.

Page 130 of 172

Page 131: Express Db Tree

TdxLookupTreeViewHierarchy Properties

TLookupTreeView component is a control that combines an edit box with a data-aware tree-view. Unit dxdbtrel DescriptionTLookupTreeView allows you to provide users with a convenient data tree view for populating the Text property that is obtained from another dataset.

Page 131 of 172

Page 132: Express Db Tree

TdxLookupTreeView.AlignmentTdxLookupTreeView

Specifies how text is aligned within the edit control. property Alignment: TAlignment; DescriptionThese are the possible values of Alignment: Value Meaning

 

taLeftJustify Align text on the left side of a column.taCenter Center text in a column.taRightJustify Align text on the right side of a column.

Page 132 of 172

Page 133: Express Db Tree

TdxTreeViewEdit.AlignmentTdxTreeView Edit

Specifies how text is aligned within the edit control. property Alignment: TAlignment; DescriptionThese are the possible values of Alignment: Value Meaning

 

taLeftJustify Align text on the left side of a column.taCenter Center text in a column.taRightJustify Align text on the right side of a column.

Page 133 of 172

Page 134: Express Db Tree

TCustomdxTreeView EventsTCustomdxTreeView  OnCustomDraw OnDragDropIsCopy OnDragDropTreeNode OnEndDragTreeNode

Page 134 of 172

Page 135: Express Db Tree

TCustomdxTreeView MethodsTCustomdxTreeView  DoCustomDraw DoDragDropTreeNode DoDragDropIsCopy

IsCustomDrawMoveTreeNodeStructure

Page 135 of 172

Page 136: Express Db Tree

TCustomdxTreeView PropertiesTCustomdxTreeView  DeletingConfirmationMessage Options SelectedIndex DragSourceTreeNode ShowNodeHint

Page 136 of 172

Page 137: Express Db Tree

TdxTreeView PropertiesTdxTreeView Derived from TCustomdxTreeView DeletingConfirmationMessage Options SelectedIndex

Page 137 of 172

Page 138: Express Db Tree

TCustomdxTreeView.DeletingConfirmationMessageTCustomdxTreeView

Specifies the message text which is displayed in the confirmation dialog box when a node is about to be deleted. property DeletingConfirmationMessage: string; DescriptionWhen an end-user is about to remove a node in the dxTreeView, a message dialog box appears provided that the trConfirmDelete flag is set in the Options property. Use the DeletingConfirmationMessage property to specify a custom message text for this dialog box.

Page 138 of 172

Page 139: Express Db Tree

TCustomdxTreeView.DoCustomDrawTCustomdxTreeView See Also

DoCustomDraw is a protected implementation method for the control's OnCustomDraw event. procedure DoCustomDraw(TreeNode : TTreeNode; Var AFont : TFont; Var AColor, ABkColor : TColor); virtual; DescriptionThe DoCustomDraw method does nothing except call any event handler attached to the OnCustomDraw event. When creating a component that descends from the TCustomdxTreeView, override the DoCustomDraw to provide other responses in addition to the inherited event-handler call. Note: This method is overridden in the dxDBTreeView controls.

Page 139 of 172

Page 140: Express Db Tree

TCustomdxTreeView.DoDragDropIsCopyTCustomdxTreeView See Also

DoDragDropIsCopy is a protected implementation method for the control's OnDragDropIsCopy event. procedure DoDragDropIsCopy(Destination, Source : TTreeNode; var IsCopy : Boolean); virtual; DescriptionThe DoDragDropIsCopy method does nothing except call any event handler attached to the OnDragDropIsCopy event. When creating a component that descends from the TCustomdxTreeView, override DoDragDropIsCopy to provide other responses in addition to the inherited event-handler call.

Page 140 of 172

Page 141: Express Db Tree

TCustomdxTreeView.DoDragDropTreeNodeTCustomdxTreeView See Also

DoDragDropTreeNode is a protected implementation method for the control's OnDragDropTreeNode event. procedure DoDragDropTreeNode(Destination, Source : TTreeNode; Var Accept : Boolean); virtual; DescriptionThe DoDragDropTreeNode method does nothing except call any event handler attached to the OnDragDropTreeNode event. When creating a component that descends from the TCustomdxTreeView, override DoDragDropTreeNode to provide other responses in addition to the inherited event-handler call.

Page 141 of 172

Page 142: Express Db Tree

TCustomdxTreeView.DragSourceTreeNodeTCustomdxTreeView

Determines the drag source tree node during drag & drop operations. property DragSourceTreeNode: TTreeNode; DescriptionRead – Only. Use DragSourceTreeNode to determine the drag source tree node during drag & drop operations. You can use it in drag & drop events.

Page 142 of 172

Page 143: Express Db Tree

TCustomdxTreeView.IsCustomDrawTCustomdxTreeView See Also

Determines whether custom draw is used. function IsCustomDraw : Boolean; virtual; DescriptionCall IsCustomDraw to determine whether custom draw is used. It returns True if custom draw is used and False if not. Custom draw is used if you write code within the OnCustomDraw event handler. Note: This method is overridden in the dxDBTreeView controls.

Page 143 of 172

Page 144: Express Db Tree

TCustomdxTreeView.MoveTreeNodeStructureTCustomdxTreeView

Moves or copies a tree node structure. function MoveTreeNodeStructure(Source, Destination : TTreeNode; IsCopy : Boolean) : TTreeNode; DescriptionThe Source parameter determines which tree node to move or copy. The Destination parameter determines where to move or copy the tree node. The Destination and Source tree node may have different TreeViews. The IsCopy parameter determines whether the structure is moved or copied. If IsCopy is True, then the structure is copied. If IsCopy is False, then the structure is moved. The result is the root of the newly created tree node structure.

Page 144 of 172

Page 145: Express Db Tree

TCustomdxTreeView.OnCustomDrawTCustomdxTreeView See Also Example

Occurs when a control is painting a particular tree node by using custom draw services and the Win32 API requests the font and color for this particular tree node. TTreeViewCustomDraw = procedure(Sender : TObject; TreeNode : TTreeNode; Var AFont : TFont; Var AColor, ABkColor : TColor) of object;

property OnCustomDraw : TTreeViewCustomDraw; DescriptionUse the OnCustomDraw event handler to implement custom draw services. The OnCustomDraw handler can set the font, color, and background color of the text for a particular TreeNode.

Page 145 of 172

Page 146: Express Db Tree

TCustomdxTreeView.OnDragDropIsCopyTCustomdxTreeView See Also Example

Occurs when a user drags an object over a control or when the user drops an object being dragged. typeTDragDropIsCopy = procedure(Destination, Source : TTreeNode;var IsCopy : Boolean) of object;property OnDragDropIsCopy : TdragDropIsCopy; DescriptionUse an OnDragDropIsCopy event to change the dxTreeView drop operation behavior. Within the OnDragDropIsCopy event handler, set IsCopy to True to copy the Source tree node and to False to move the Source tree node. The Source is the tree node being dragged, the Destination is the selected drop target tree node.

Page 146 of 172

Page 147: Express Db Tree

TCustomdxTreeView.OnDragDropTreeNodeTCustomdxTreeView See Also Example

Occurs when a user drags an object over a control or when the user drops an object being dragged. TDragDropTreeNode = procedure(Destination, Source : TTreeNode; Var Accept : Boolean) of object;property OnDragDropTreeNode : TDragDropTreeNode; DescriptionUse an OnDragDropTreeNode event to signal that the dxTreeView has to copy. Within the OnDragDropTreeNode event handler, set the Accept parameter to False to reject the dragged object. Set Accept to True to allow the user to drop the dragged object on the control. The Source is the tree node being dragged, the Destination is the selected drop target tree node.

Page 147 of 172

Page 148: Express Db Tree

TCustomdxTreeView.OnEndDragTreeNodeTCustomdxTreeView See Also Example

Occurs when a drag & drop operation is successfully finished and before the tree-node(s) (records for data-aware TreeView) are moved (added). TEndDragTreeNode = procedure(Destination, Source : TTreeNode;Var AttachMode : TNodeAttachMode) of object;property OnEndDragTreeNode : TEndDragTreeNode; DescriptionWrite an OnEndDragTreeNode event handler to change the default behavior of the dxTreeView on Drop operation. The Destination and Source variants are the destination and Source tree nodes. The AttachMode variant is a set of the possible ways in which the Source can be attached to the Destination. The default value of the AttachMode is naAddChild. Set AttachMode to:

naAdd Adds the source to the end of the list of the Destination;naAddFirst Adds the source at the beginning of the list of the Destination;naAddChild Adds the source as a child of the destination at the end of the child list;naAddChildFirst Adds the source as a child of the destination at the beginning of the child list

of the destination;naInsert Inserts the source after the destination node.

Page 148 of 172

Page 149: Express Db Tree

TCustomdxTreeView.OptionsTCustomdxTreeView

Specifies various behavioral properties of the dxTreeView. typeTdxTreeViewOption = (trCanDelete, trConfirmDelete);TdxTreeViewOptions = set of TdxTreeViewOption;property Options : TdxTreeViewOptions; DescriptionSet Options to include the desired properties for the dxTreeView. Options is a set drawn from the following values:  Value Meaning

 

trCanDelete Delete the selected tree node and its structure, when the user presses Delete.

trConfirmDelete A message box appears, asking for confirmation, when the user presses Delete to remove a node in the dxTreeView. The trCanDelete must also be set.

Page 149 of 172

Page 150: Express Db Tree

TCustomdxTreeView.SelectedIndexTCustomdxTreeView

Specifies the index in an image list to be used when an item is selected. property SelectedIndex : Integer; DescriptionUse SelectedIndex to specify the index in an image list to be used when an item is selected.

Page 150 of 172

Page 151: Express Db Tree

TCustomdxTreeView.ShowNodeHintTCustomdxTreeView

Determines if a dxTreeView should display a tree node hint when the mouse pointer rests momentarily on a tree node.  property ShowNodeHint : Boolean; DescriptionSet ShowNodeHint to False to prevent tree node hints from displaying within all Express TreeViews. Note: Tree node hint behavior depends on your commctrl.dll version.

Page 151 of 172

Page 152: Express Db Tree

TdxDBTreePrintData PropertiesTdxDBTreePrintData  MaxLevelCount DataSource KeyField LevelCount ParentField RootValue

Page 152 of 172

Page 153: Express Db Tree

TdxDBTreeQRBand PropertiesTdxDBTreeQRBand  DataSource IndentationWidth

Page 153 of 172

Page 154: Express Db Tree

TdxDBTreePrintData.DataSourceTdxDBTreePrintData See Also

Identifies the link to a self-referenced dataset from where TdxDBTreePrintData locates its data. property DataSource : TDataSource; DescriptionSet DataSource to the TDataSource object that links to a self-referenced dataset from where the TdxDBTreePrintData should fetch its data.

Page 154 of 172

Page 155: Express Db Tree

TdxDBTreePrintData.KeyFieldTdxDBTreePrintData See Also

Identifies the KEY field of a self-referenced dataset. property KeyField: string; DescriptionSet the KeyField property to the KEY field of the self-referenced dataset. The dataset is specified by a data source component (TDataSource).

Page 155 of 172

Page 156: Express Db Tree

TdxDBTreePrintData.LevelCountTdxDBTreePrintData

Specifies the level’s number that TdxDBTreePrintData can load.  property LevelCount : Integer; DescriptionSet LevelCount to specify the level’s number that TdxDBTreePrintData can load. If the LevelCount equals 0, then TdxDBTreePrintData loads 'root' records and all their children recursively. If the LevelCount equals 1, then TdxDBTreePrintData loads only 'root' records. If the LevelCount equals 2, then TdxDBTreePrintData loads 'root' records and their 'nearest' children, etc.

Page 156 of 172

Page 157: Express Db Tree

TdxDBTreePrintData.MaxLevelCountTdxDBTreePrintData

Determines the maximum level number in TdxDBTreePrintData. property MaxLevelCount : Integer; DescriptionRun-time and Read-Only. Use MaxLevelCount to determine the maximum level number in TdxDBTreePrintData.

Page 157 of 172

Page 158: Express Db Tree

TdxDBTreePrintData.ParentFieldTdxDBTreePrintData See Also

Identifies the PARENT field of a self-referenced dataset. property ParentField: string; DescriptionSet the ParentField property to the PARENT field of a self-referenced dataset. The dataset is specified by a data source component (TDataSource).

Page 158 of 172

Page 159: Express Db Tree

TdxDBTreePrintData.RootValueTdxDBTreePrintData See Also

Determines the KEY field Value. property RootValue : String; DescriptionUse RootValue to specify the 'root' record. You can make any record of a self-referenced DataSet the root record of TdxDBTreePrintData. If the RootValue is different from NULL, then TdxDBTreePrintData will load only the record whose KEY value equals RootValue and all its children (the children are loaded recursively).

Page 159 of 172

Page 160: Express Db Tree

TdxDBTreeQRBandHierarchy Properties

TdxDBTreeQRBand control is the QRBand that allows easily making the Quick report with the self-referenced dataset. Unit dxdbtrqr DescriptionUse TdxDBTreeQRBand to make the Quick report with the self-referenced dataset. TdxDBTreeQRBand increases the left property of its child controls depending on the IndentationWidth and the TdxDBTreePrintDataSet record Level.

Page 160 of 172

Page 161: Express Db Tree

TdxDBTreeQRBand.DataSourceTdxDBTreeQRBand See Also

DataSource identifies the link to the TdxDBTreePrintData dataset. property DataSource : TDataSource; DescriptionSet DataSource to identify the link to the TdxDBTreePrintData dataset.

Page 161 of 172

Page 162: Express Db Tree

TdxDBTreeQRBand.IndentationWidthTdxDBTreeQRBand

IndentationWidth specifies the indentation in pixels for one level. property IndentationWidth : Integer; DescriptionUse IndentationWidth to specify in pixels the indentation for one level. TdxDBTreeQRBand increases the left property of its child controls in the following way:for I := 0 to ControlCount - 1 do Controls[I].Left := Controls[I].Left + IndentationWidth * DBTreeQRBand.FindField('dx$level').AsInteger; 

Page 162 of 172

Page 163: Express Db Tree

Unit dxdbtrqr ControlsTdxDBTreeQRBand

Page 163 of 172

Page 164: Express Db Tree

Example This example shows how to use the OnCustomDraw event. Nodes that have a KeyValue less than 150 are drawn with bold font style and blue font color, while all other nodes are drawn with the Red color style on a yellow background. procedure TForm1.DBTreeView1CustomDraw(Sender: TObject;TreeNode: TTreeNode; AFont: TFont; var AColor, ABKColor: TColor); VarKeyValue : Integer; beginif VarIsNull(TdxDBTreeNode(TreeNode).KeyFieldValue) then exit; //Get Key Value of a particular node. KeyValue := TdxDBTreeNode(TreeNode).KeyFieldValue; //Change the Font Style, Color and Background Color of a node based on it's KeyValue; if(KeyValue < 150) then begin AFont.Style := [fsBold]; AColor := clBlue; end else begin ABKColor := clYellow; AColor := clRed; end; end;

Page 164 of 172

Page 165: Express Db Tree

Example In this example we use the OnNewKeyValue to get the KeyValue for a newly created node from DB. procedure TForm1.dxDBTreeViewCreateNewKeyValue(Sender: TObject;var NewKeyValue: Variant); beginGetMaxIdQuery.SQL.Clear; GetMaxIdQuery.SQL.Add('Select max(id) From Products'); GetMaxIdQuery.Open; NewKeyValue := GetMaxIdQuery.Fields[0].AsInteger + 1; GetMaxIdQuery.Close; end;

Page 165 of 172

Page 166: Express Db Tree

Example In this example we use the OnAddNewItem event and the BkColor, Color, FontStyle, FontName and IsCustomDraw properties of the TdxDBTreeNode to implement custom drawing in a TdxDBTreeView. procedure TForm1.dxDBTreeView1AddNewItem(Sender: TObject;var DBTreeNode: TdxDBTreeNode); begincase Table1.FindField('state').AsInteger of 0: with DBTreeNode do begin FontStyle := []; Color := clGreen; BkColor := clWhite; end; 1: with DBTreeNode do begin FontStyle := [fsBold]; Color := clRed; BkColor := clYellow; end; 2: with DBTreeNode do begin FontStyle := [fsBold]; Color := clWhite; BkColor := clBlack; end; 3: with DBTreeNode do begin FontStyle := [fsItalic]; Color := clBlue; BkColor := clWhite; end; 4: with DBTreeNode do begin FontStyle := [fsUnderLine]; Color := clSilver; BkColor := clWhite;  end; end; DBTreeNode.IsCustomDraw := True; end;

Page 166 of 172

Page 167: Express Db Tree

Example In this example we use the OnEndDragTreeNode event to change the drag & drop behavior of the TdxTreeView in the following way: If the Source and Destination tree nodes are at the same level, then the source tree node is inserted before the destination (Default Behavior – the source tree node becomes the last child tree node of the destination).  procedure TForm2.DBTreeView1EndDragTreeNode(Destination, Source: TTreeNode;var AttachMode: TNodeAttachMode); begin// naAdd, naAddFirst, naAddChild, naAddChildFirst, naInsert if Destination.Level = Source.Level then AttachMode := naInsert; if Destination.Level = Source.Level - 1 then AttachMode := naAddChild;  end;

Page 167 of 172

Page 168: Express Db Tree

Example In this example we use the OnSetDisplayItemText event to change the text of tree nodes based on the tree node level. Tree nodes may display any text, but you will can only edit Text that is required from the field – ListField.  procedure TForm1.dxDBTreeViewSetDisplayItemText(Sender: TObject;var DisplayText: string);Vartr : TTreeNode; begin// Get TreeNodetr := dxDBTreeView.DBTreeNodes.GetTreeNode(TreeQueryID.Value);if tr <> Nil then beginif tr.Level mod 2 = 1 thenDisplayText := Field1.Textelse DisplayText := Field2.Text;end; end;

Page 168 of 172

Page 169: Express Db Tree

Example In this example we use the DBTreeNodes.MaxKeyFieldValue property of a dxDBTreeView to set up the KeyField in a Table. procedure TForm1.T1AfterInsert(DataSet: TDataSet);beginif varIsNull(T1.FindField('pr_id').Value) then begin if varIsNull(dxDBTreeView1.DBTreeNodes.MaxKeyFieldValue) then T1.FindField('pr_id').AsInteger := 0 else T1.FindField('pr_id').Value := dxDBTreeView1.DBTreeNodes.MaxKeyFieldValue + 1; end; end;

Page 169 of 172

Page 170: Express Db Tree

Example In the following example, we disable drag & drop for root nodes. procedure TForm1.DBTreeView1DragDropTreeNode(Destination,Source: TTreeNode; var Accept: Boolean); beginAccept := Not (Source.Parent = Nil); end;

Page 170 of 172

Page 171: Express Db Tree

Example In the following example, we copy the tree node structure during drag & drop even if the user does not press the CTRL key. procedure TForm1.DBTreeView2DragDropIsCopy(Destination, Source: TTreeNode;var IsCopy: Boolean); beginIsCopy := True; end;

Page 171 of 172

Page 172: Express Db Tree

Example In this example we display the number of children of a selected node. This code should be used only with the SmartRecordLoad option. procedure TForm1.Button1Click(Sender: TObject);beginif dxDBTreeView1.Selected <> nil then begin with TdxDBTreeNode(dxDBTreeView1.Selected) do begin //Check if child records are loaded. if ChildLoaded then ShowMessage(IntToStr(Count)) else begin //Load child records ChildLoaded := True; ShowMessage(IntToStr(Count)); ChildLoaded := False; end; end; end; end;

Page 172 of 172