Tips for using the tadvstringgrid Control

Source: Internet
Author: User

Http://www.delphibbs.com/keylife/iblog_show.asp? Xid = 24767 Monopoly

This article briefly introduces some common property events and methods of the tadvstringgrid control, mainly used for statistics and complex table design! Core Part: several functions and processes for merging cells!

1. Can I edit it?
Set goediting to true in options.

2. When you click the mouse, you can edit the row or column width directly, or you can set the row or column width in mouseactions.

3. set the data format of a column in the grid. The predefined formats are:
Enum teditortype {ednormal, edspinedit, edcomboedit, edcombolist, ededitbtn, edcheckbox, eddateedit, eddateeditupdown, edtimeedit, edbutton, example, ednumeric, example, edfloat, edcapital, edmixedcase, edpassword, eduniteditbtn, edlowercase, eduppercase, example, edtimespinedit, eddatespinedit, example, example, edcusto M, edrichedit, ednone, eduniedit, edunicomboedit, edunicombolist};
set through the ongeteditortype () event, for example:
void _ fastcall tform1 :: editgridgeteditortype (tobject * sender, int ACOl, int Arow, teditortype & aeditor)
{< br> switch (ACOl) {
case 1: aeditor = edcombolist; break; // set the first column as ComboBox type input
case 2: aeditor = ededitbtn; break; // set the second column as editbtn type input. A Selection box is displayed.
case 3: aeditor = edspinedit; br Eak; // set the third column as spinedit type input
case 4: aeditor = eddateedit; break; // set the fourth column as date type input. The datetimepicker is displayed.
}< BR >}

4. the input and output of each format in tadvstringgrid must correspond, otherwise it cannot be recognized during loading (because the storage formats of various types of files are different ). For example:
If tadvstringgrid: savetofile () is used for saving, tadvstringgrid: loadfromfile () is used for loading. Other mappings are as follows:
Tadvstringgrid: loadfrombinfile ();?? Tadvstringgrid: savetobinfile ();
Tadvstringgrid: loadfromcsv ();?? Tadvstringgrid: savetocsv ();
And so on.

5. added the drop-down lists of edcomboedit and edcombolist:
Method:
Tadvstringgrid: clearcombostring (void); // clear the existing drop-down list
Tadvstringgrid: addcombostring (ansistring S );
Tadvstringgrid: ComboBox-> sorted = true;
You can use ComboBox to access the properties and methods of the built-in combo control.

6. Added edcheckbox interface processing
After loading data in the grid, use:
Tadvstringgrid: void _ fastcall addcheckbox (INT ACOl, int Arow, bool state, bool data) method to add checkbox interface processing.
For example:
For (I = 1; I <editgrid-> rowcount; I ++)
Editgrid-> addcheckbox (5, I, false, false );

7. Use the tadvstringgrid: spinedit object to access the features of the built-in spinedit class;
In the same way, other built-in objects can access the attributes of these classes and execute the methods of these classes.

8. Sorting Problem in tadvstringgrid:
First, set the sorting parameter through the tadvstringgrid: sortsettings attribute (published tsortsettings class as an attribute ).
Call the tadvstringgrid: qsort () method to apply sortsettings.
Sorting direction: sortsettings-> direction = Enum {sdascending, sddescending };
Sort column: sortsettings-> column = 3;

9. The tadvstringgrid: autosize attribute automatically sets the column width, which is not recommended. After automatic adjustment, it is really ugly.

10. multi-row display
Bool tadvstringgrid: multilinecells attribute. Whether multi-row display is supported. If yes, you can use "#13" as the separator to insert multiple-row strings and use multiple-row display.
You can use wordwrap to support multi-row display.
When setting and canceling multi-line display, tadvstringgrid: defaultrowheight is also set, which will have a good effect.

11. To set certain rows or columns for fixed display, use the onisfixedcell () event handle to handle the display. Call the tadvstringgrid: repaint () method to make the setting take effect.
For example:
If (colfix-> checked) {// colfix is a tcheckbox
Advstringgrid1-> repaint ();
}
// Event handling handle
Void _ fastcall tform1: advstringgrid1isfixedcell (tobject * sender,
Int Arow, int ACOl, bool & isfixed)
{
If (ACOl = 3) & (colfix-> checked ))
Isfixed = true; else isfixed = false;
}

12. Processing display style, such as adding a currency prefix and Physical Quantity Unit
In the tadvstringgrid: ongetformat () event processing handle.
Set the display prefix for the aprefix parameter;
Asuffix parameter settings display suffix;
Astyle parameter Enum tsortstyle {ssautomatic, ssalphabetic, ssnumeric, ssdate, algorithm, ssalphacase, algorithm, ss1_dateus, algorithm, ssfinancial, algorithm, algorithm, ssraw, sshtml, ssimages, sscheckbox, ssunicode }; set the sorting style;

13. Can I edit a specific cell?
Use the tadvstringgrid: oncaneit () event handle to handle the event,
Set the bool & canedit parameter to edit certain cells.

14. Hide and display certain cells
Tadvstringgrid: unhidecolumn (INT ACOl)
Tadvstringgrid: hidecolumn (INT ACOl );

15. Search implementation:
Tadvstringgrid: Find ()
Tadvstringgrid: findnext ();
Two methods return the tpoint type,
Find () requires a tfindparams type parameter, Enum tfindparameters {fnmatchcase, fnmatchfull, fill, fill, fnmatchstart, fnfindincurrentrow, fnfindincurrentcol, fill, success, fail, fnbackward, success }; you can design a search form by yourself.
For example:
// ---------- Findfirst ----------
Void _ fastcall tform1: findfirst1click (tobject * sender)
{
Tfind * Find;
Tfindparams findparams;
Tpoint res;

Find = new tfind (form1 );

If (find-> showmodal () = mrok)
{
If (find-> chkcase-> checked) findparams <fnmatchcase;
If (find-> chkfull-> checked) findparams <fnmatchfull;
If (find-> chkregular-> checked) findparams <fnmatchregular;
If (find-> Dir-> itemindex = 1) findparams <fndirectionleftright;
If (find-> where-> itemindex = 1) findparams <fnfindincurrentcol;
If (find-> where-> itemindex = 2) findparams <fnfindincurrentrow;

Res = advstringgrid1-> findfirst (find-> findtext-> text, findparams );
If (res. x> = 0)
{
Advstringgrid1-> Col = res. X;
Advstringgrid1-> ROW = res. Y;
}
Else
Showmessage ("text not found ");
}
Delete find;
}
// ---------- Findnext ----------
Void _ fastcall tform1: findnext1click (tobject * sender)
{
Tpoint res;

Res = advstringgrid1-> findnext ();

If (res. x> = 0) & (res. Y> = 0 ))
{
Advstringgrid1-> Col = res. X;
Advstringgrid1-> ROW = res. Y;
}
Else
Showmessage ("text not found ");
}
//----------

16. tadvstringgrid: ints [int ACOl] [int Arow] Access cells with integer values. If reading fails, an exception is triggered.

17. process the alignment of a specific cell
Add the tadvstringgrid: ongetalignment event processing handle.

18.
(1). Add the icon tadvstringgrid: addicon ();
Prototype: void _ fastcall addicon (INT ACOl, int Arow, graphics: ticon * aicon, tcellhalign Hal, tcellvalign Val)
(2) Add a rotation Font: tadvstringgrid: addrotated;
Prototype: void _ fastcall addrotated (INT ACOl, int Arow, short aangle, ansistring S );
(3) Remove the image from imagelist and add it to the cell: tadvstringgrid: addimageidx;
Prototype: void _ fastcall addimageidx (INT ACOl, int Arow, int aidx, tcellhalign Hal, tcellvalign Val );
The aidx parameter indicates the image index in imagelist.
(4). Add a bitmap to the cell: tadvstringgrid: addbitmap;
Prototype: void _ fastcall addbitmap (INT ACOl, int Arow, graphics: tbitmap * abmp, bool transparent, tcellhalign Hal, tcellvalign Val );
Whether the bool transparent parameter is transparent.
(5) automatically add the number: autonumbercol
Tadvstringgrid: autonumbercol (INT ACOl) method, numbers the specified column from 1, not the column number in the fixed row;
Purpose: generate an automatic number for the first column.
(6) add multiple images to the cell: tadvstringgrid: addmultiimage
Prototype: void _ fastcall addmultiimage (INT ACOl, int Arow, int Dir, tcellhalign
Hal, tcellvalign Val );
In fact, we only declare to the system that this cell will place multiple images and add images through gridimages. For example:
Advstringgrid2-> addmultiimage (5, 1, 0, habeforetext, vacenter );

Advstringgrid2-> cellimages [5] [1]-> Add (0 );
Advstringgrid2-> cellimages [5] [1]-> Add (1 );
(7). If the tadvstringgrid: enablehtml attribute is enabled, enter HTML in the cell.Source codeIt will be displayed in HTML format, for example:
Advstringgrid2-> cells [7] [1] = "Easy html
Formatting ";
Advstringgrid2-> cells [7] [2] = "including

Advstringgrid2-> cells [7] [3] = "enjoy
----------

Minihtml ";

Advstringgrid2-> cells [7] [4] ="
Advstringgrid2-> cells [7] [5] = "125 <sup> 9 </sup>/<sub> 16 </sub> ";
The content will be displayed in HTML format in tadvstringgrid.
(8 ). you can use the tadvstringgrid: RichEdit attribute to call the built-in RichEdit class of tadvstringgrid. It is a RichEdit editor that can be used to process documents in the RTF format and then use the tadvstringgrid.
Prototype: void _ fastcall richtocell (INT Col, int row, comctrls: trichedit * richeditor );
You can clear RichEdit using tadvstringgrid: RichEdit: clear (), add the content again, and then add it to the cell.
You can use tadvstringgrid: RichEdit: selattributes to adjust the RichEdit format.
(9). Use the tadvstringgrid: addprogress method to add progress bars to cells.
Prototype: void _ fastcall addprogress (INT ACOl, int Arow, graphics: tcolor fgcolor, graphics: tcolor bkcolor );
The cell's integer is the current progress value. You can use tadvstringgrid: ints [col, row] to access this value.
(10). Use the tadvstringgrid: addcomment method to add comments.
Prototype: void _ fastcall addcomment (INT ACOl, int Arow, ansistring comment );
After a comment is added, a small red triangle number is displayed in the upper right corner of the cell. For example:
Advstringgrid2-> addcomment (8, 3, "This is a custom" "\ x00d" "comment for this cell ");
Advstringgrid2-> cells [8] [3] = "cell
Comment ";
(11). Use tadvstringgrid enhanced HTML syntax to parse and add links between internal cells. For example:
Advstringgrid2-> cells [8] [4] = "advstringgrid2-> cells [8] [5] =" (12). Use tadvstringgrid: addbutton to add buttons to cells.
Prototype: void _ fastcall addbutton (INT ACOl, int Arow, int BW, int BH, ansistring caption, tcellhalign Hal, tcellvalign Val );
When the added button is pressed, The onbuttonclick event is triggered (? Tested, cannot touch this event ).

19. In the tadvstringgrid: ongetcellscolor () event processing handle, you can set the color and font of cells.

21. add nodes that can be shrunk and look similar to a group,
Method:
Tadvstringgrid: fixedcols = 0;
Tadvstringgrid: fixedcolwidth = 20;
Tadvstringgrid: addnode (2, 4 );
Tadvstringgrid: addnode (7,2 );
Tadvstringgrid: addnode (13, 4 );
Tadvstringgrid: addnode () method prototype:
Void _ fastcall addnode (INT Arow, int span); the second parameter is the stride of the group.

22. Expand All nodes: tadvstringgrid: expandall () method
Shrink all nodes: tadvstringgrid: contractall () method
Tadvstringgrid: cellnode-> nodetype = cnflat;
Tadvstringgrid: cellnode-> nodetype = cn3d;
Tadvstringgrid: cellnode-> nodetype = cnglyph;
The preceding three attributes set the node display style when stringgrid displays nodes.

23. Add filter to tadvstringgrid
A pre-defined filter class in tadvstringgrid: tfilterdata
For example:
Tfilterdata * FD;

Advstringgrid3-> filter-> clear ();

FD = advstringgrid3-> filter-> Add ();

FD-> condition = combox1-> items-> strings [combox1-> itemindex];
FD-> column = 1;

FD = advstringgrid3-> filter-> Add ();

FD-> con_dition = combox2-> items-> strings [combox2-> itemindex];
FD-> column = 3;

Advstringgrid3-> filteractive = true;

24. Auto adjust the column width autosizecolumns
Prototype: void _ fastcall autosizecolumns (const bool dofixedcols, const int padding)
Use the second parameter to specify the additional space required after automatic adjustment

25. tadvstringgrid printing.
Use tadvpreviewdialog to connect to tadvstringgrid for preview. This control provides an interface to localize the interface directly.
Use the print () method of tadvstringgrid to print. Print settings adjust attributes of the tadvstringgrid: tprintsettins class

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.