The dataset is processed as a visual tree, and the data grid automatically adapts to the width.

Source: Internet
Author: User
Description: The structure title of the table that processes the parent node Id field, the node text field, and the node Id field. The dataset is processed as a visual tree, and the data mesh automatically adapts to the width of jackgao Delphi notes-delphi2007.net.
Http://www.delphi2007.net/delphiblog/html/delphi_200351493500194.html///////Begin Sourcefunction DataSetToTreeNode (mDataSet: TDataSet; mFieldNameParent: string; // parent node identification field name fields: string; // node text field name fields: string; // node identification field name mTreeView: TTreeView; mTreeNode: TTreeNode; mParentText: string): Boolean; varvTreeNode: TTreeNode; vFieldValues: Variant; vFieldNames: string; beginResult: = False; if not Assigned (mDataSet) then Exit; if not Assigned (mTreeView) then Exit; if not mDataSet. active then Exit; vFieldNames: = Format ('% s; % s', [mFieldNameParent, mFieldNameTreeText, mFieldNameTreeId]); mDataSet. filtered: = False; mDataSet. filter: = Format ('% s = % s', [mFieldNameParent, QuotedStr (mParentText)]); mDataSet. filtered: = True; if mDataSet. recordCount = 0 then Exit; mDataSet. first; while not mDataSet. eof do beginvTreeNode: = mTreeView. items. addChild (mTreeNode, mDataSet. fieldByName (mFieldNameTreeText ). asString); vFieldValues: = mDataSet [vFieldNames]; DataSetToTreeNode (mDataSet, mFieldNameParent, mFieldNameTreeText, delimiter, mTreeView, vTreeNode, mDataSet. fieldByName (mFieldNameTreeId ). asString); ////// Begin restore location mDataSet. filtered: = False; mDataSet. filter: = Format ('% s = % s', [mFieldNameParent, QuotedStr (mParentText)]); mDataSet. filtered: = True; mDataSet. locate (vFieldNames, vFieldValues, []); // End restore location mDataSet. next; end; Result: = True; end; ///// End Source // Begin Demoprocedure TForm1.Button1Click (Sender: TObject); beginTreeView1.Items. clear; DataSetToTreeNode (Table1, 'parenttreeid', 'treetext ', 'treeid', TreeView1, nil, 'null'); end; ////// End Source: automatically adapts to the width of the Data Grid. Description: Use DBGrid. ////// Begin SourceusesMath; function DBGridRecordSize (mColumn: TColumn): Boolean; {whether the maximum display width of the returned record data mesh is successful} beginResult: = False; if not Assigned (mColumn. field) then Exit; mColumn. field. tag: = Max (mColumn. field. tag, TDBGrid (mColumn. grid ). canvas. textWidth (mColumn. field. displayText); Result: = True; end; {DBGridRecordSize} function DBGridAutoSize (mDBGrid: TDBGrid; mOffset: Integer = 5): Boolean; {whether the returned data mesh automatically adapts to the width} varI: Integer; beginResult: = False; if not Assigned (mDBGrid) then Exit; if not Assigned (mDBGrid. dataSource) then Exit; if not Assigned (mDBGrid. dataSource. dataSet) then Exit; if not mDBGrid. dataSource. dataSet. active then Exit; for I: = 0 to mDBGrid. columns. count-1 do beginif not mDBGrid. columns [I]. visible then Continue; if Assigned (mDBGrid. columns [I]. field) thenmDBGrid. columns [I]. width: = Max (mDBGrid. columns [I]. field. tag, mDBGrid. canvas. textWidth (mDBGrid. columns [I]. title. caption) + mOffsetelse mDBGrid. columns [I]. width: = mDBGrid. canvas. textWidth (mDBGrid. columns [I]. title. caption) + mOffset; mDBGrid. refresh; end; Result: = True; end; {DBGridAutoSize} // End Source // Begin Demoprocedure TForm1.DBGrid1DrawColumnCell (Sender: TObject; const Rect: TRect; DataCol: Integer; Column: TColumn; State: TGridDrawState); values (Column); end; procedure TForm1.Button1Click (Sender: TObject); beginDBGridAutoSize (DBGrid1); end; //// // End Demo
 

  • Progress in reading Cal3d models in DELPHI
  • Read and Write Paradox tables using ADO
  • Solution for dynamically generated controls that cannot be displayed
  • This note is taken from waterspace
  • PBL File Format
  • Pb key commands
  • Favorites
  • PowerPoint
  • Batch update
  • When the parameter is set
  • Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.