ExpressQuantumGrid4 cxGrid usage and experience
1. A brief introduction: cxGrid1Level1 in the lower right of cxGrid indicates the layer of the Grid table. cxGrid can have multiple layers, which is equivalent to a collection of PageControl
Feature, while cxGrid1DBTableView1 on the Right of cxGrid1Level1 is equivalent to DBGrid. Right-click cxGrid1 to add cxGrid1Level2, right-click
CxGrid1Level2, you can select Create View, Add level or Delete Level. Add level can Add sub-Level, Create View
You can select multiple views of different general classes. Where
1) the DB Table can be connected to the View of the database, and the more general DBGrid is similar, it is more than DBGrid, such as the middle mouse button can be used, can be used for statistics,
Query, and other functions;
2) DB Banded Table can be implemented as follows:
---------------------------------
| Description 1 | description 2 |
---------------------------------
| Field 1 | field 2 | field 3 | field 4 |
And other similar functions;
3) DB Card View provides the Card-based data display function, which is suitable for personnel file management;
4) do not repeat the rest.
2. Some usage methods:
1) examples with images and MEMO:
Drag a cxGrid1, Table1, and performance1. Set DatabaseName of Table1 to DBDEMOS, TableName to biolife. db,
Set Active to DataSet of TrueataSource1 to Table1; DataSource in DataController of cxGrid1DBTableView1
Set to performance1; right-click cxGrid1DBTableView1 and select Create All Columns; double-click cxGrid1. In the displayed window, find
CxGrid1DBTableView1Notes and cxGrid1DBTableView1Graphic set their Properties to BlobEdit. Run the command to see
Result. Set the Properties attribute of cxGrid1DBTableView1Graphic to Image, and then set Stretch under Properties to True,
Set cxGrid1DBTableView1-> optionsview-> CellAutoHeight to True to see the result.
2) how to make "Drag a column here to group by that column" not displayed
Solution: Click cxGrid1DBTableView1 on cxGrid1.
In cxGrid1DBTableView1-> optionsview-> groupbybox: = false
Note: many attributes in OptionsView may be used frequently, such as ColumnAutoWith and Navigator.
3) How can I change the English [Drag a column header to group by that column] On GroupPanel to Chinese?
Solution: the simplest method is TcxGridTableView. OnCustomDrawPartBackground. OnCustomDrawGroupCell can also be used:
Procedure TForm1.cxGrid1DBTableView1CustomDrawPartBackground (
Sender: TcxGridTableView; ACanvas: TcxCanvas;
AViewInfo: TcxCustomGridCellViewInfo; var ADone: Boolean );
Begin
AViewInfo. Text: = 'dynamically set the display content of groupbox ';
ACanvas. FillRect (AViewInfo. Bounds );
End;
4) how to implement the following functions:
+ Finance Department
+ Raw material warehouse
+ Finished product Library
+ Stamping Workshop
+ Software Development Department
This is the department name. Click the plus sign to display the Department staff.
Solution: in fact, this is a master-slave table relationship. 1: Fill in the keyfieldnames of the master table.
2: Fill in keyfieldnames from the table
3: complete the detaikeyfieldNames and masterkeyfieldnames of the slave table.
4: the data source from the table must be sorted by the fields associated with the master table.
Note: If the Master/Slave Table structure is set elsewhere, it cannot be displayed, for example, the mastersource and
Asterfield cannot display data! If there is a master-slave relationship between the two cxgrids, the settings are OK.
5) statistical functions
Solution: cxGrid1DBTableView1-> optionsview-> Footer is set to True.
CxGrid1DBTableView1-& gtataController-> Summary: Set FooterSummaryItems.
6) display similar to PageControl
Solution: Add a Level, set cxGrid1-> RootLevelOptions-& gtetailTabsPosition to dtpTop, and set the Caption values of cxGrid1Level1 and cxGrid1Level2 accordingly.
Not complete .........
The above are some of the problems encountered when using cxGrid. I have summarized some of them and there are still many problems to be solved. Here, I hope that people who have used cxGrid will help me sum up, so that later scholars can avoid detours!
7) how to set the columns on the left to prevent scrolling?
Solution: DB Banded Table can be used,
Create Band0 and Band1 in cxGrid1DBBandedTableView
Fixed = tfLeft of Band0
Fixed = tfnone of Band1
Set the BandIndex of the field to be locked to 0. If the other value is 1, it will be OK.
8) How to Implement functions like EXCEL, such as the current grid = G14 + G15 + G16
Solution: a simple example: label1.Caption: = cxGrid1DBTableView1. DataController. Values [2,
3] + cxGrid1DBTableView2. DataController. Values [1, 1] + cxGrid1DBTableView3. DataController. Values [1, 1];
Therefore, data in different cxGrid1DBTableView tables can be assigned to the current grid, so that the current grid in EXCEL is equivalent to G14 + G15 + G16.
9) Right-click cxGrid1DBBandedTableView1 and choose Edit Layout from the menu?
Solution: You can drag fields and drag them in parallel into a sense of modularity (layers). The arrows are displayed when you drag them, that is, you can drag a field to put it.
To the top, you can group records by this field. Click a field, and a small triangle will appear above or below.
The role of a triangle is to sort the data in ascending or descending order according to the field.
Another Set as Default parameter is used to maintain the current TableView parameter. When a new TableView is generated, it can be the same as the parameter that was last saved.
10) How to import data from cxGrid to EXCEL, HTML, XML, and TEXT
Solution: This problem becomes very simple after cxGrid is used,
Uses
CxExportGrid4Link;
Procedure TForm1.Button1Click (Sender: TObject );
Begin
ExportGrid4ToEXCEL ('d: \ wang. xsl ', cxGrid1, True, True );
ExportGrid4ToTEXT ('d: \ wang.txt ', cxGrid1, True, True );
ExportGrid4ToXML ('d: \ wang. xml', cxGrid1, True, True );
ExportGrid4ToHTML ('d: \ wang.html ', cxGrid1, True, True );
End;
11) how to make the data that meets the conditions display different colors?
Solution:
Var
AYellowStyle: TcxStyle;
Procedure TForm1.FormCreate (Sender: TObject );
Begin
// Row color
AYellowStyle: = TcxStyle. Create (Self );
AYellowStyle. Color: = $0080 FFFF;
AYellowStyle. TextColor: = clMaroon;
End;
Procedure TForm1.cxGrid1DBBandedTableView1StylesGetContentStyle (
Sender: TcxCustomGridTableView; ARecord: TcxCustomGridRecord;
AItem: TcxCustomGridTableItem; out AStyle: TcxStyle );
Begin
If ARecord. Values [cxGrid1DBBandedTableView1Lengthcm. Index] <81 then
AStyle: = AYellowStyle;
End;
Here cxGrid1DBBandedTableView1Lengthcm. When the Index is smaller than 81, It is yellow.
Question 12) How do I import files from external TXT files to cxGrid?
Solution: procedure CustomizeColumns;
Procedure LoadData;
Procedure TForm1.CustomizeColumns;
Const
CDistance = 1;
CRadius = 5;
CPeriod = 4;
CPstring = 0;
Var
I: Integer;
Begin
DecimalSeparator: = '.';
With cxGrid1TableView2 do
For I: = 0 to ColumnCount-1 do
If I in [cDistance, cRadius] then
Columns [I]. DataBinding. ValueTypeClass: = TcxIntegerValueType // column 1 and 5 are Integer
Else
If I in [cPstring, cPeriod] then
Columns [I]. DataBinding. ValueTypeClass: = TcxStringValueType // Columns 0 and 4 are strings.
Else
Columns [I]. DataBinding. ValueTypeClass: = TcxFloatValueType; // other values are Float.
End;
Procedure TForm1.LoadData;
Const
AFileName = 'Assets and liabilities table .txt ';
AHeaderLineCount = 2;
Var
ARecords, AValues: TStringList;
I: Integer;
Procedure InitRecord (const Str: string );
Var
J: Integer;
V: Variant;
Begin
AValues. CommaText: = Str;
For J: = 0 to AValues. Count-1 do
If AValues. Strings [J] <> '-'Then
Begin
V: = AValues. Strings [J];
If not VarIsNull (V) then
CxGrid1TableView2. DataController. Values [I, J]: = V;
End;
End;
Begin
If not FileExists (AFileName) then
Raise Exception. Create ('data file not found ');
ARecords: = TStringList. Create;
AValues: = TStringList. Create;
With ARecords do
Try
LoadFromFile (AFileName );
CxGrid1TableView2. BeginUpdate;
CxGrid1TableView2. DataController. RecordCount: = Count-AHeaderLineCount;
For I: = 0 to Count-(AHeaderLineCount + 1) do
InitRecord (Strings [I + AHeaderLineCount]);
Finally
CxGrid1TableView2. EndUpdate;
ARecords. Free;
AValues. Free;
End;
End;
Procedure TForm1.FormCreate (Sender: TObject );
Begin
CustomizeColumns;
LoadData_Zcfz;
End;
Among them, the data in the assets and liabilities table .txt is as follows:
Number of assets at the beginning of the year at the end of the number of liabilities and owner equity at the beginning of the year at the end of the number
---------------------------------------------------------
Current Assets: 1 0.00 0.00 current liabilities: 2 0.00 0.00
13) how to change the column color?
Var
AFirstColumnStyle: TcxStyle;
Procedure TForm1.FormCreate (Sender: TObject );
Begin
// Column color
AFirstColumnStyle: = TcxStyle. Create (Self );
AFirstColumnStyle. Color: = clAqua;
AFirstColumnStyle. TextColor: = clBlue;
CxGrid1TableView1. Columns [1]. Styles. Content: = AFirstColumnStyle;
End;
14) How to Use Set as default?
Solution: Set as default is used to Set parameters conveniently, for example:
After the database is connected, change cxGrid1DBBandedTableView1-<OptionsCustomize-> ColumnFiltering to False. (This setting can remove the field name drop-down list.) Change cxGrid1DBBandedTableView1-<OptionsView-> Navigator to True. Right-click cxGrid1DBBandedTableView1 and click Set as default in the pop-up menu bar.
OK. The next time you generate a new cxgrid1dbbandedtableview1, these settings are the same as the one you just made. This set as default is useful when many parameters need to be set!
15) How does one change the color of the text in the corresponding cell when the mouse moves?
Solution:
VaR
Ftrackitem: tcxcustomgridtableitem;
Ftrackrec: tcxcustomgridrecord;
Procedure tform1.cxgrid1dbtableview1customdrawcell (
Sender: tcxcustomgridtableview; acanvas: tcxcanvas;
Aviewinfo: tcxgridtabledatacellviewinfo; var Adone: Boolean );
Begin
If (aviewinfo. gridrecord = ftrackrec) and (aviewinfo. Item = ftrackitem) then
Begin
Acanvas. Font. Color: = clred; // red font
Acanvas. Font. Style: = [fsunderline]; // underlined
End;
End;
Procedure tform1.cxgrid1dbtableview1mousemove (Sender: tobject;
Shift: tshiftstate; X, Y: integer );
VaR
Ahittest: tcxcustomgridhittest;
Atrackitem: tcxcustomgridtableitem;
Atrackrec: tcxcustomgridrecord;
Begin
Atrackitem: = ftrackitem;
Atrackrec: = ftrackrec;
Ahittest: = (sender as tcxgridsite). gridview. viewinfo. gethittest (x, y );
If ahittest is tcxgridrecordcellhittest then
Begin
Ftrackitem: = tcxgridrecordcellhittest (ahittest). item;
Ftrackrec: = tcxgridrecordcellhittest (ahittest). gridrecord;
End
Else
Begin
Ftrackitem: = nil;
Ftrackrec: = nil;
End;
If (atrackitem <> ftrackitem) or (atrackrec <> ftrackrec) then
Begin
// Invalidate old cell
If atrackrec <> nil then
Atrackrec. invalidate (atrackitem );
// Invalidate new cell
If FTrackRec <> nil then
FTrackRec. Invalidate (FTrackItem );
End;
End;
16) how to design a cxGrid with multiple headers?
Solution: cxGrid solves the following headers:
---------------------------------
| Description 1 | description 2 |
---------------------------------
| Field 1 | field 2 | field 3 | field 4 |
| Field 5 | field 6 |
| Field 7 | field 8 | field 9 |
This is easy to implement. You can drag the field name directly on the top, and the arrow will be displayed when you drag the field, and the position you want to display will be OK. Alternatively, you can right-click cxGrid1DBBandedTableView1 and choose Edit Layout.
However, cxGrid cannot implement the following multi-Header Format:
---------------------------------
| Description 1 | description 2 |
---------------------------------
| Description 3 | description 4 | description 5 | description 6 |
| Field 1 | field 2 |
| Field 3 | field 4 | field 5 |
I don't know who can achieve this multi-header?
17) in the master-slave table structure, when "+" is clicked, how does one aggregate the focus on the records of the corresponding master table?
Solution:
Var
HitTest: TcxCustomGridHitTest;
Procedure tcolumnsincludemomainform. tvProjectsMouseDown (Sender: TObject;
Button: TMouseButton; Shift: TShiftState; X, Y: Integer );
Begin
// Note that the Sender parameter is a Site
HitTest: = (Sender as TcxGridSite). GridView. ViewInfo. GetHitTest (X, Y );
// The point belongs to the [+]/[-] button area
If HitTest is TcxGridExpandButtonHitTest then
// Move focus to the record
TcxGridExpandButtonHitTest (HitTest). GridRecord. Focused: = True;
End;
769 Words • 48 views • 07-02-09 • 10:34:50 • GAO Yukun <a href = "src =" http: // ***/blogs/rsc/icons/envelope.gif "width =" 13 "http: blogs blog = '17 & title = expressquantumgrid4c_cxgridc_ac_ao_afic _ 1 & more = 1 & c = 1 & tb = 1 & pb = 1 "'index. php> export data from grid Category:
Delphi
You can use a grid to export data directly.
The ExportGrid4ToExcel function provides the ability to export grid data to files in the cxExportGrid4Link package.
The ShellExecute Function has the file opening function in ShellAPI.
Code:
ExportGrid4ToExcel (AppRootDir + 'production plan directive ', grdWorkOrder, True, 'xls ');
Try
ShellExecute (handle, nil, PChar (AppRootDir + 'production plan directive .xls '), nil, nil, SW_SHOWNORMAL );
Except
ShowMessage ('excel is not installed on the local machine. This function can only run on a computer with EXCEL installed! ');
Abort;
End;
If you want to export the same font and color as the grid, use the TcxStyleRepository control to create a TcxStyle and set its color and font, assign this TcxStyle to the Content and Header in the Styles attribute of TcxGridDBTableView.
39 Words • 51 views • 07-02-07 • 17:12:39 • GAO Yukun <a href = "src =" http: // ***/blogs/rsc/icons/envelope.gif "width =" 13 "http: blogs blog = '17 & title = cf_anfamfa_oa_da_r & more = 1 & c = 1 & tb = 1 & pb = 1 "'index. php> about the grid color Category:
Delphi
Procedure TForm. cxGrid1DBTableView1StylesGetContentStyle (
Sender: TcxCustomGridTableView; ARecord: TcxCustomGridRecord;
AItem: TcxCustomGridTableItem; out AStyle: TcxStyle );
Begin
If ARecord is TcxGridDataRow and not ARecord. Selected then
Begin // clnEngineer. Index can also be an integer of 1, 2, 3
If ARecord. Values [clnEngineer. Index] = Null then
AStyle: = sty1 // sty1 is a child of TcxStyleRepository
Else if ARecord. Values [clnEnginneerUserID. Index] = UserId then
If (ARecord. Values [clnNotOddState. Index] = 'process processing') or
(ARecord. Values [clnNotOddState. Index] = 'process assist ') then
AStyle: = sty2 // sty2 is a child of TcxStyleRepository
End;
End;
After parsing, AStyle has two basic attributes: 1-Color 2-TextColor.
Color: Grid background Color
TextColor: The font color in the grid.
Compare the properties of the TcxStyleRepository Control
I can see why I can assign a child in TcxStyleRepository to AStyle!
71 Words • 71 views • 06-12-05 • 18:01:32 • sun shall <a href = "src =" http: // ***/blogs/rsc/icons/envelope.gif "width =" 13 "http: blogs blog = '19 & title = a_sao_cf_anfc_ec_e_s & more = 1 & c = 1 & tb = 1 & pb = 1 "'index. php> when the cxgrid record is selected, change the background color of the selected record (Blue by default) Category:
Delphi
Procedure TM7_BugManagementForm.tvQryCustomDrawCell (
Sender: TcxCustomGridTableView; ACanvas: TcxCanvas;
AViewInfo: TcxGridTableDataCellViewInfo; var ADone: Boolean );
Begin
If ADone or AViewInfo. Selected then
Begin
ACanvas. Font. Color: = clBlack;
ACanvas. SetBrushColor (clWhite );
End;
End;
30 Words • 86 views • 06-11-15 • 16:16:47 • Kong Ling new <a href = "src =" http: // ***/blogs/rsc/icons/envelope.gif "width =" 13 "http: blogs blog = '20 & title = af_e_acscxgriderdaf_a_p_sa_ecle_erdaf _ & more = 1 & c = 1 & tb = 1 & pb = 1 "'index. php> cxGrid knowledge point Category:
DevExpress
- When TableView. OptionsView. HeaderAutoHeight is set to True, the column title height is automatically adjusted.
- Records are selected on the grid. when the focus is removed, the selected records are not displayed. Solution: Modify the TableView attribute and set OptionsSelection-> HideSelection to False.
- Traverse selected records:
With ATableView. DataController do
Begin
VOldFocusedRecordIndex: = FocusedRecordIndex;
For vindex: = 0 to atableview. Controller. selectedrowcount-1 do
Begin
Focusedrecordindex: = atableview. Controller. selectedrows [vindex]. recordindex;
Aqry. updateobject. execsql (ukinsert );
End;
Focusedrecordindex: = voldfocusedrecordindex;
End;
- Traverse all records in the current view:
With ATableView. DataController do
Begin
VOldFocusedRecordIndex: = FocusedRecordIndex;
For vindex: = 0 to filteredrecordcount-1 do
Begin
Focusedrecordindex: = filteredrecordindex [vindex];
AQry. UpdateObject. ExecSQL (ukInsert );
End;
FocusedRecordIndex: = VOldFocusedRecordIndex;
End;
- Call the DataController. Groups. FullExpand method of TableView to expand all nodes.
- When a custom data source is used to delete a record, BeginUpdate is performed first, and then EndUpdate is completed. Otherwise, the index is occasionally thrown out of the range:
TvProducePlan. BeginUpdate;
Try
FCustomDataSource. DeleteSelectedRecord (GetSelectedIds );
Finally
TvProducePlan. EndUpdate;
End;
- Obtain the value of a column in the selected record:
Function TMainForm. GetSelectedIds: TStringArray;
Var
VIndex: Integer;
Begin
SetLength (Result, tvProducePlan. Controller. SelectedRowCount );
For VIndex: = 0 to tvProducePlan. Controller. SelectedRowCount-1 do
Result [VIndex]: = tvProducePlan. DataController. Values [tvProducePlan. Controller. SelectedRecords [VIndex]. RecordIndex, 0];
End;
- Locate another grid based on the data of a grid:
Procedure TMainForm. LinkFocusRecord (AParentColumn, AChildColumn: TcxGridColumn; AParentGrid, AChildGrid: TcxGridTableView );
Var
VIndex: Integer;
VValue: STring;
FocusedRecord: TcxGridFocusedRecordChangedEvent;
Begin
FocusedRecord: = AParentGrid. OnFocusedRecordChanged;
Aparentgrid. onfocusedrecordchanged: = nil;
Try
With achildgrid. datacontroller do
Begin
Vvalue: = getdisplaytext (focusedrecordindex, achildcolumn. Index );
End;
VIndex: = AParentGrid. DataController. FindRecordIndexByText (0, AParentColumn. Index, VValue, False, False, True );
If VIndex <0 then
Begin
AParentGrid. DataController. ClearSelection;
Exit;
End;
AParentGrid. DataController. FocusedRecordIndex: = VIndex;
AParentGrid. DataController. SyncSelectionFocusedRecord;
Finally
AParentGrid. OnFocusedRecordChanged: = FocusedRecord;
End;
End;
- The focusedrecordchanged event of tableview indicates that the current focus record has changed.
- Use toprowindex and leftpos of tcxgridtableview. Controller to obtain or set the top line number and left position of the current visible View