DBGRID uses the book (5)

xiaoxiao2021-03-06  64

In DBGRID, how can I let me click on a cell to choose a whole line, and edit the content of the cell? During the design, sometimes the data is large, when Field is more, just clicking the cell may make a Field data error (such as data missed line), to think about this problem, the solution is as follows: Click on a single element to change the current line color. This approach is also a way to have no way!

type TMyDBGrid = class (TDBGrid); //// DBGrid1.Options-> dgEditing = True // DBGrid1.Options-> dgRowSelect = Falseprocedure TForm1.DBGrid1DrawColumnCell (Sender: TObject; const Rect: TRect; DataCol: Integer; Column: TColumn ; State: TGridDrawState); begin with TMyDBGrid (Sender) do begin if DataLink.ActiveRecord = Row-1 then begin Canvas.Font.Color: = clWhite; Canvas.Brush.Color: = $ 00800040; end else begin Canvas.Brush.Color : = Color; canvas.font.color: = font.color; end; defaultdrawcolumncell (Rect, Datacol, Column, State); End;

Test Pass (D7)! Double-click DBGRID sorting (wants users to double-click on a field of DBGIRD control, ascending, then double-click, descending sequence ...?) Procedure TForm1.dbgrid1titleclick (Column: tcolumn); var temp, title: string; begin Temp : = Column.fieldname; qusp.close; if column.index <> LastColumn dam If (POS ('', dbgrid1.columns [LastColumn] .title.caption> 0) OR (POS ('', dbgrid1 .Columns [lastColumn] .Title.Caption)> 0) then DBGrid1.Columns [lastColumn] .Title.Caption: = Copy (DBGrid1.Columns [lastColumn] .Title.Caption, 3, Length (DBGrid1.Columns [lastColumn]. Title.caption) - 2); Qusp.sql [ICOUNT]: = 'Order by' Temp 'ASC'; dbgrid1.columns [color1.columns [color1.columns [column] = '↑' .Index] .title.caption; LastColumn: = column.index; end else begin lastcolumn: = column.index; title: = dbgrid1.columns [LastColumn] .title.caption; if Pos ('', title)> 0 The begin Qusp.sql [iCount]: = 'Order By' Temp 'DESC'; DELETE (Title, 1, 2); dbgrid1.columns [LastColumn] .title.caption: = '↓' title; Else IF POS ('', title)> 0 THEN Begin Qusp.sql [ICOUNT]: = 'ORDER BY' TEMP 'ASC'; DELETE (Title, 1, 2); DBGRID1.COLUMNS [LastColumn] .title.caption: = '↑' Title; Else Begin Qusp.sql [iCount]: = 'Order by' Temp 'ASC'; dbgrid1.columns [LastColumn] .title.caption: = '' title; end; end; QUSP.OPEN; END;

DBGRID control hides or displays the title bar DBGRID control Hide or displays the title bar 1. New a process with two parameters (the first parameter is the menu object, the second is the DBGRID control): Procedure ViewTitle (Sender: Tobject; DBGColumns: TDBGRID); // Hide or display the DBGRID Title Bar 2, then press CTRL SHIFT C key keys, the defined process will appear in the implementation portion. Procedure FrmStock.ViewTitle (Sender: TObject; DbgColumns: TDBGrid); begin With (Sender as TMenuItem) do begin Checked: = not Checked; DbgColumns.Columns [Tag] .Visible: = Checked; end; end;

3. Set the tag of the menu subkey to correspond to the COLUMNS value of DBGRID, such as: DBGRID has a title bar is the 'date' at the 0 column, and then set the TAG of the menu of the column to 0 to 0.

4. Select the onClick event of the menu to the ViewTitle. DBGRID How to appear in the non-Bul field bar to display the DataSet of DBGRID to display the special content field to the explicit field in the ONGETTEXT event to write the following code: take the table: Procedure TFORM1.TABLE1MYFIELD1GETTEXT (Sender: Tfield VAR text: string; displaytext: boolean; var pd: string; begin inherited; pd: = table1.fieldbyname ('myfield1'). Asstring; if pd = '1' Then Text: = '□' else if Pd = '2' Ten Text: = '▲ Else text: =' √ '; end; how to automatically scroll the displayed data with DBGRID or DBGRIDEH? Procedure TForm1.Timer1Timer (Sender: Tobject); Varm: tMSG: = WM_VScroll; M.WParamlo: = SB_Linedown; M.WParamhi: = 1; M.LParam: = 0; PostMessage (Self.dbgrid1.Handle , M.MSG, M.WParam, M.LParam;

END;

Procedure TFORM1.BUTTON1CLICK (Sender: TOBJECT); beginself.timer1.enabled: = true;

If you need to let him automatically roll from beginning to tail, add the following code if table1.eof kilnsle1.first; two design comparisons in DBGRID List, DBGRID Dress List implements a drop-down list in the DBGRID grid, Set the Picklist string list of this field in DBGRID, the initial number value DropdownRows. Taking the origin field (string type) in the staff information library as an example, the specific design steps are as follows: 1. Place Table1, DataSource1, DBGRID1, DBNAVIGATOR1, etc. on the form, press the table to set the properties of each object:

------------------------------------------------------ --------------------------------- Table1 Database SY1 TABLENAME ZGK.DBF // Staff Information Library DataSource1 Dataset Table1dbGrid1 DataSource Datasource1dbnavigator1 DataSource Datasource1 -------------------------------------------- 2, double click on Table1, In the pop1.table1 window that pops up, use the right-click to pop up the shortcut menu, click the Add Fields menu item; after selecting all the fields, press the OK button.

3. Modify the DISPLAYLABEL attribute of step 2's new field. Take the table1zgbh field as an example, select Table1zGBH in the Object Inspector window, modify the property DisplayLabel = employee number, and the remaining fields are similar. 4. Double-click DBGRID1. In the pop-up DBGRID1.COLUMNS window, click the Add All Fields button to increase all fields of Table1.

5, in the Editing DBGRID1.COLUMNS window, select JG this line, switch to the Object Inspector window, modify its picklist.strings as "Zhejiang, Zhejiang, Hubei, Zhejiang, Zhejiang, China"

6. Write a statement in the Form1.onCreate event:

Table1.open;

7, F9 runs, click on a recorded born field with the mouse, and a button appears on the right, click this button to display a drop-down list, including the four rows of strings entered in step 5, and can be selected with the mouse. Of course, you can also enter a string in the drop-down list.

Second, the search in DBGRID finds a field called lookup field (Lookup Field), the value of a key field in dbgrid comes from the corresponding field of another database. Using Find field technology, not only can effectively avoid input errors, but also DBGRID's display mode is more flexible, and the key fields are not displayed, and the data of another field corresponding to the source database is displayed.

For example, we display and edit employee information in dBGrid, including employee numbers, employee names, origin, unit numbers, and unit numbers come from another database table - unit library, called "unit number". If we directly display and edit the unit number, it will face 1, 2, 3, etc., very intuitive numbers, and the editor is extremely easy to go wrong. But if the display and editing is the corresponding unit name in the unit library, it will be very intuitive. This is the benefit of the supported find field supported by DBGRID.

Realizing the DBGRID Find fields also does not require any statement, the specific design steps are as follows: 1. Place Table1, Table2, DataSource1, DBGRID1, DBNAVIGATOR1, etc. on the form, press the table to set the properties of each object: ----- ---------------------------------- Object properties set value ----------- ---------------------------- Table1 Database Sy1 TableName ZGK.DBF // Store Table2 Database Sy1 Tablename DWK.DBF // Unit Information Library Datasource1 DataSet Table1DBGrid1 DataSource Datasource1dbnavigator1 Datasource Datasource1 ----------------------------------------- -2, double-click Table1, in the pop-up FORM1.TABLE1 window, use the right-click to pop up the shortcut menu, click the Add Fields menu item; after selecting all the fields, press the OK button.

3. Modify the DISPLAYLABEL attribute of step 2's new field. Take the table1zgbh field as an example, select Table1zGBH in the Object Inspector window, modify the property DisplayLabel = employee number, and the remaining fields are similar.

4, set table1dwbh.visible = false.

5, in the Form1.Table1 window, use the right-click to pop up the shortcut menu, click the New Field menu item, add a lookup field DWMC, set the corresponding properties in the pop-up window, press the OK button to confirm; in the Object Inspector window, set Table1DWMC. DisplayLabel = Unit name.

6. Write the statement in the Form1.oncreate event: table1.open;

7. Press F9 to run, when the light is shifted to a recorded unit name field, click on the field with the mouse, that is, a drop-down list, click the lower arrow on the right, and select it in the drop-down list. It can be seen here that the contents of the drop-down list come from the unit library and cannot enter other content.

Third, the drop-down list and find fields in DBGRID Although the drop-down list and lookup field in dbgrid appear in the form of the following list, there is a big difference.

1. Use the drop-down list set by the PickList property, and its data is manually entered, although it can also be modified in the program, but the dynamic characteristics clearly extract data from the additional database table directly.

2. Use the drop-down list set by the PickList property, allowing input to not belong to the data in the drop-down list, but only enters the data in the key field in the source database in the Find field, which ensures the integrity of the data.

3. The drop-down list design set with the PickList property is simpler.

转载请注明原文地址:https://www.9cbs.com/read-89394.html

New Post(0)
CopyRight © 2020 All Rights Reserved
Processed: 0.035, SQL: 9