DBGRID application

xiaoxiao2021-03-05  25

Dawa Forum Copyright Keylife Map Note Author   Archonwang Title  : DBGrid Application Book (Comprehensive Revision is working) Keywords: Category: Development Experience Skin: Open (Rating: ★★★★, Reply: 29, Read : 5682) ?? In the Delphi language database programming, DBGRID is one of the main means of displaying data. However, DBGRID default appearance has not seen monotonous and lack of ideas. In fact, we can fully achieve the purpose of beautifying DBGRID in our program. By programming, we can change DBGRID's head, grid, grid line foreground and background color, and the size and style of the related font. The following sample program demonstrates settings for DBGRID attributes, making the table displayed by Delphi as beautiful as the form in the web page. The operation of the sample program: Place the DBGRID1, Query1, DataSource1 on Form1, set the related properties, so that the DBGRID1 can display the data in the table. Then, type the following code in DBGRID1's OnDrawColumnCell event, and then run the program, you can see the magical result. This code is debugged in the Windows98, Delphi5.0 environment.

procedure TMainForm.DBGrid1DrawColumnCell (Sender: TObject; const Rect: TRect; DataCol: Integer; Column: TColumn; State: TGridDrawState); var i: integer; begin if gdSelected in State then Exit; file: // font definition table and header Background color: for i: = 0 TO (sender as tdbgrid) .COLUMNS.COUNT-1 Do Begin (Sender as tdbgrid) .COLUMNS [i] .title.font.name: = 'Song Body'; File: // Font ( Sender as tdbgrid) .COLUMNS [i] .title.font.size: = 9; file: // font size (sender as tdbgrid) .COLUMNS [i] .title.font.color: = $ 000000FF; file: // Font Color (red) (red) (red) .COLUMNS [i] .title.color: = $ 0000FF00; file: // background color (green) end; file: // Value change grid background color: if query1.Recno MOD 2 = 0 THEN (Sender as tdbgrid) .canvas.brush.color: = clinfobk file: // Define background color else (sender as tdbgrid) .canvas.brush.color: = RGB (191, 255, 223); file : // Define background color file: // Defines the color of the grid line: DBGrid1.defaultdrawColumnCell (Rect, Datacol, Column, State); with (Sender AS TDBGRID) .canvas do file: // draws the Border of Cell Border Begin Pen. Color: = $ 00ff0000; File: // Define Brush Color (Blue) Moveto (Rect.Left, Rect.Bottom); File: // Brush positioning lineto (Rect.right, Rect.bottom); file: // Draw blue horizontal Pen.Color: = $ 0000FF00; file: // Define brush color (green) Moveto (Rect.right , RECT.TOP); File: // Brush positioning lineto (Rect.right, Rect.bottom); file: // Draw green vertical line end; end; 2003-11-5 17:30:00 commented ?? ?

2003-11-5 17:31:41 There is still this way, before you don't devexpress ... I will add it.

2003-11-11 17:07:42 Problem: Delphi5 - Valve Change DBGRID Grid Color Place DBGRID1, Query1, DataSource1 on Form1, sets the relevant properties, so that the DBGRID1 can display the data in the table. Then, type the following code in the onDrawColumnCell event of DBGRID1, then run the program

Code: Procedure TFORM1.DBGRID1DRAWCOLUMNCELL (Sender: Tobject; Const: TRECT; Datacol: Integer; Column: Tcolumn; State: TgriddrawState;

Var i: integer; begin if gdselected in state dam; file: // Value change grid background color: if adoquery1.recno mod 2 = 0 Then (Sender as tdbgrid) .canvas.brush.color: = Clinfobk file: / / Define background color else (sender as tdbgrid) .canvas.brush.color: = RGB (191, 255, 223); file: // Define background color file: // Define Grid line Color: dbgrid1.defaultdrawColumnCell (Rect) , Datacol, Column, State; With (sender as tdbgrid) .canvas do file: // draws Cell Border Begin Pen.Color: = $ 00ff0000; File: // Define Brush Color (Blue) Moveto (Rect.Left) , Rect.Bottom; File: // Brush positioning lineto (Rect.right, Rect.Bottom); file: // Draw blue horizontal Pen.Color: = CLBTNFACE; file: // Define brush color (blue ) MoveTo (Rect.right, Rect.top); File: // Brush Positioning Lineto (Rect.right, Rect.Bottom); File: // Draw Green End; End;

Table1 in BDE fails to pass, and the color has no interlaced changes.

2003-11-11 17:12:09 Inserting other visual component Delphi in Delphi's DBGRID provides powerful DBGRID components to facilitate database application design. But if we use the DBGRID component, each get the focus (Grid) is just a simple text editing box, which is not convenient for users to enter data. Delphi also provides some other data components to facilitate user input, such as DBCombOBox, Dbcheckbox, etc., but these components have no DBGRID functionality. Can Delphi can make DBGRIDs like Visual FoxPro can be other visual data components to facilitate users? In fact, we can achieve this by inserting other visual components in DBGRID.

Delphi's internal mechanism for DBGRID is a component-dbedit component that floats on the grid. The grid you enter the data is actually a floating dbedit component, and the other unfolded places is just an image. So, inserting other visual components in DBGRID is a visual component that floats on the grid. Thus any component, including from a simple dbcheckbox to complex dialog box, can be inserted in DBGRID. Below is a step of inserting a DBCOMBOBOX component in DBGRID, using the same approach to insert other components.

1, create a new project in Delphi 4.0.

2, Data Access component board dragged on DataSource, Table, Data Controls component board on DBGRID, DBCOMBOBOX, four components to FORM1.

3. Set the properties of each component as follows:

rcf1 object properties set plant Form1 Caption 'SpinEdit inserted DBGrid components of the example in the' DataSource1 DataSet Table1Table1 DatabaseName DBDEMOSTableName 'teacher.DBF'Active TrueDBGrid1 DataSource DataSource1DBComboBox1 DataField SEXDataSource DataSource1Visible FalseStrings Items.' M '|' female 'Note: I'm here with TEACHER.DBF, it is to reflect the gender of the teachers, can only be "male" or "female".

4, DrawDATACELL event is to draw cells, when the field corresponding to the focus grid is consistent with the fields corresponding to the combo box, the moving combination box is on the grid that gets the focus, and the combo box is visible, thereby reaching in DBGRID The function of displaying DBCOMBOBOX is displayed on the column. Set the onDrawDataacell event of DBGRID1 as follows:

procedure TForm1.DBGrid1DrawDataCell (Sender: TObject; const Rect: TRect; Field: TField; State: TGridDrawState); begin if (gdFocused in State) then begin if (Field.FieldName = DBComboBox1.DataField) then begin DBComboBox1.Left: = Rect .Left DBGrid1.Left; DBComboBox1.Top: = rect.Top DBGrid1.top; DBComboBox1.Width: = Rect.Right - rect.Left; DBComboBox1.Height: = rect.Bottom - rect.Top; DBComboBox1.Visible: = True; End; end;

5 is not displayed when DBComboBox DBGrid specified cell is not in focus, the set DBGrid1 OnColExit event follows: procedure TForm1.DBGrid1ColExit (Sender: TObject); begin If DBGrid1.SelectedField.FieldName = DBComboBox1.DataField then begin DBComboBox1.Visible: = false ; End;

6. When DBGRID specifies the column to get focus, the DrawDataAsell event is just drawing a cell and displays dbcomboBox, but DBCOMBOBOX does not get focus, and the input of the data is on the cell. Tune the SendMessage this Windows API function in DBGRID1, which is transferred to DBCOMBOBOX, which reaches data input on DBCOMBOBOX. So set the keypress event as follows:

procedure TForm1.DBGrid1KeyPress (Sender: TObject; var Key: Char); begin if (key <> chr (9)) then begin if (DBGrid1.SelectedField.FieldName = DBComboBox1.DataField) then begin DBComboBox1.SetFocus; SendMessage (DBComboBox1. Handle, WM_CHAR, WORD (KEY), 0); End; End; End; Program in Chinese Windows 98, Delphi 4.015 is debugged. I hope this article can make you more convenient and quick to develop database applications.

2003-11-11 17:17:56 Locking the column of DBGRID I am using Delphi3 to program the database programming, I hope that the DBGRID component can be like a Browse command like FoxPro when displaying the data. The few columns do not scroll left. , What method is applied?

We know that Delphi's TStringGrid has a property fixedcols to specify columns that do not scroll. Although TDBGRID cannot use this property directly, it is also possible to first function by forced type conversion, because both classes come from the TCUSTOMGRID class. Below we describe the specific usage as the DELPHI 3.0 Demos / DB / Ctrlgrid as an example. Add the following line during the TFMCTRLGRID.FORMSHOW of this example:

TstringGrid (dbgrid1) .fixedcols: = 2;

Run the program, when moving each column or so, the Symbol column will not move. In addition to this method, the following method can be used: first in the FORM declaration part

TYPE TMYGRID = Class (TDBGRID) End;

Then add in the TFMCTRLGRID.FORMSHOW process:

TMYGRID (DBGRID1) .fixedcols: = 2;

The two are slightly different from the form, but the essence is the same. We set FixedCOLS here for 2 because there is an indication column on the left side of the DBGRID component. If you set the DGIndicator of DBGRID to false, you should set FixedCOLS 1.

2003-11-11 17:21:36 Making DBGRID a few profiles You can change the color of the lattice or text in the DRAWDATACELL event of the DBGRID component. Such as:

OnDrawDataacell (...) Begin with Tdbgrid (Sender) Do Begin IF (Condition) Then Can CANVAS.TEXTOUT (Rect.Left 4 Rect.top 2

'The text to display, such as the form of the form');

And you will see how the DBGRID's display is overlapping. It is because the information overlap the data to be displayed by DBGRID and the data displayed by Textout: the field added in the Query component (right button on the component) Fields ... Player is set to false in the ONGETTEXT event that does not display the information.

Procedure TFORM1.Query1detail1getText (Sender: Tfield; DIST: STRING; DISPLAYTEXT: BOOLEAN); Begin // Decide not to display the obtained information false -> not display // to avoid TEXTOUT when DBGRID knows table information. Text overlapping Displaytext: = false; end; end; if it is easy to use with Delphi 3. For example: the value of a fraction in the table is black and other as black words. In dbgrid.ondrawcolumncell (...) :

Begin if Tablefield.asinteger <0 the dbgrid.canvas.font.color: = CLRED Else dbgrid.canvas.font.color: = CLBLACK; DBGRID.DEFAULTDRAWCOLUMNCELL (...); END;

This is still not necessary to rewrite the format specified for Field.

2003-11-11 17:25:29 Practical Delphi Data Grid Color Special Effects Delphi Data Grid Control (TDBGRID) plays a very important role in displaying and editing a large amount of data in the database; however, in use data grid While controlling the control, the operator is dazzling because of the large amount of data in the form. How to improve the ease of use of grid controls, overcome this shortcomings? This paper puts forward a solution from changing the color configuration angle of the data grid.

The following is the implementation method of the six special effects of the data grid control, as for how the data grid control and the data set are connected to the number.

1. Longitudinal zebra crossing effect: The odd number of the grid and the even column are displayed in different colors to distinguish between adjacent data columns. File: // Write the following code in DBGRID DrawColumnCell event:

Case Datacol Mod 2 = 0 OFTRUE: dbgrid1.canvas.brush.color: = CLBLUE; File: // Even Blue False: dbgrid1.canvas.brush.color: = Claqua; file: // 奇 列 用用 绿End; dbgrid1.canvas.pen.mode: = pmmask; dbgrid1.defaultdrawColumnCell (RectDataColColumnTate);

2. Longitudinal zebra crossing while highlighting the current cell effect: to highlight the currently selected field.

File: // Modify the above code to: Case Datacol MOD 2 = 0 OFTRUE: DBGRID1.CANVAS.BRUSH.COLOR: = CLBLUE; File: // Even Columns with Blue False: DBGrid1.canvas.brush.color: = Claqua ; file: // odd column with light green End; If ((State = [gdSelected]) or (State = [gdSelectedgdFocused])) thenIf Not DbGrid1.SelectedRows.CurrentRowSelected thenDbGrid1.Canvas.Brush.Color: = clRed; file: // The currently selected cell display red dbgrid1.canvas.pen.mode: = pmmask; dbgrid1.defaultdrawColumnCell (Rect Datacol Column State);

The above two methods highlight the display effect of the column.

3. The currently selected row is highlighted in the data grid. Set the DGROWSELECT attribute in the options attribute of the DBGRID control. The color property is written in Claqua (background color) in DBGRID DrawColumnCell event: if (state = [gdselected]) or (state = [gdselected gdfocused]))) Thendbgrid1.canvas.brush.color: = CLRED; File: // The current line is displayed in red, and other rows use the light green dbgrid1.canvas.pen.mode: = pmmask; dbgrid1.defaultdrawcolumn (RectDataColColumnState);

4. The zebra crossing effect: highlights the current line and distinguishes different columns (fields).

File: // Other Properties Set the same 3, modify the above code to: IF (state = [gdselected]) or (state = [gdselectedGDFocused])) Thenbegincase Datacol Mod 2 = 0 OFTRUE: dbgrid1.canvas.brush.color: = CLRED; File: // The no-numbers of the currently selected row show red false: dbgrid1.canvas.brush.color: = CLBLUE; File: // The odd number of the currently selected row shows blue end; dbgrid1.canvas.pen.mode : = pmmask; dbgrid1.defaultdrawColumnCell (RectDataColcolumnState); END;

5. Transverse zebra crossing while highlighting the current effect.

File: // Other Properties Set the same 3, modify the above code to: Case Table1.Recno Mod 2 = 0 of file: // Depending on the record number of the data set True: dbgrid1.canvas.brush.color: = Claqua; File: // Even Light Green Display False: DBGrid1.canvas.brush.Color: = CLBLUE; File: // 数 Row Blue Represents End; IF ((state = [gdselected]) or (state = [gdselected ])) The file: // Select the row red display dbgrid1.canvas.brush.color: = CLRED; dbgrid1.canvas.pen.mode: = pmmask; dbgrid1.defaultdrawColumnCell (RectDataColColumnState);

6. Two-way zebra crossing effect: that is, the line is distinguished in different colors, while the line is divided into different columns in longitudinal zebra crossing.

File: // Other Properties Set the same 3, modify the above code to: Case Table1.Recno Mod 2 = 0 of file: // Depending on the record number of the data set True: dbgrid1.canvas.brush.color: = Claqua; File: // Even Light Green Display False: DBGrid1.canvas.brush.Color: = CLBLUE; File: // 数 Row Blue Represents End; IF ((state = [gdselected]) or (state = [gdselected ])) Thencase Datacol MOD 2 = 0 OFTRUE: DBGRID1.CANVAS.BRUSH.COLOR: = CLRED; File: // The ever-numbered number of red FALSE: DBGRID1.cANVAS.BRUSH.COLOR: = CLGreen; File: / / The odd-numbered column of the currently selected line indicates the green represents End; dbgrid1.canvas.pen.mode: = pmmask; dbgrid1.defaultdrawColumnCell (RectDataColColumnState); The above two methods are set on the column of data grid controls, respectively, Readers can set special effects according to their needs. This program is tested in Delphi5.

2003-11-13 11:11:31 Click DBGRID Title to sort Query Results Keywords: DBGRID Sort

To achieve the title of DBGRID, you want to make a general program, not a general program, such as increasing the order by ... A Title is also sorted separately, the purpose is to want to do so like the resource manager.

procedure TFHkdata.SortQuery (Column: TColumn); var SqlStr, myFieldName, TempStr: string; OrderPos: integer; SavedParams: TParams; begin if not (Column.Field.FieldKind in [fkData, fkLookup]) then exit; if Column.Field .FieldKind = fkData then myFieldName: = UpperCase (Column.Field.FieldName) else myFieldName: = UpperCase (Column.Field.KeyFields); while Pos (myFieldName, ';') <> 0 do myFieldName: = copy (myFieldName, 1 , POS (MyfieldName, ';') - 1) ',' Copy (MyfieldName, POS (MyfieldName, ';') 1,100); with tQuery (tdbgrid (column.grid) .datasource.Dataset) Do Begin SQLSTR : = Uppercase (SQL.Text); // if Pos (MyfieldName, Sqlstr) = 0 THEN EXIT; if Paramcount> 0 THEN SAVEDPARAMS: = TParams.create; SavedParams.assign (PARAMS); End; Orderpos: = POS 'ORDER', SQLSTR); IF (Orderpos = 0) or (POS (MyfieldName, Copy (Sqlstr, Orderpos, 100)) = 0) Tenstr: = 'ORDER BY' Myfieldname 'ASC' Else IF POS (' ASC ', SQLSTR) = 0 THEN TEMPSTR: =' ORDER BY ' MyfieldName ASC' Else Tempstr: = 'Order By' MyfieldName 'DESC'; if Orderpos <> 0 Then Sqlstr: = COPY (SQLSTR, 1, ORDERPOS-1); SQLSTR: = SQLSTR TEMPSTR; Active: = false; sql.clear SQL.TEXT: = SQLSTR; if paramcount> 0 Then Begin params.assignvalues ​​(savedparams); SavedParams.Free; end; prepare; open; end; end; 2003-11-13 11:13:57 Remove DBGRID automatic addition Function Keywords: dBGRID

When moving to the last record, press "Next" to add a record, if you remove this function procedure tform1.datasource1change (Sender: Tobject; Field: tfield); begin if tdataroup (sender) .Dataset.eof kil dam TDataSource ( Sender) .Dataset.cancel; end; 2003-11-16 12:05:46 DBGRID does not support the mouse up and down mobile solution (thanks WangXian11) you capture WM_MouseWheel message processing private OldGridWnd: Twndmethod; Procedure NewGridWnd (Var Message: TMESSAGE); public

procedure TForm1.NewGridWnd (var Message: TMessage); var IsNeg: Boolean; begin if Message.Msg = WM_MOUSEWHEEL then begin IsNeg: = Short (Message.WParamHi) <0; if IsNeg then DBGrid1.DataSource.DataSet.MoveBy (1) Else dbgrid1.datasource.DataSet.moveby (-1) end else ildwnd (message);

Procedure tform1.form; begin oldgridwnd: = dbgrid1.windowProc; dbgrid1.windowproc: = newgridwnd;

2003-11-17 14:46:56 DBGRID moving focus to the specified row and column DBGRID is inherited from Tcustomgrid, it has a COL and ROW attribute, but it is protected, you can't access it directly, to process it, you can do this :

TDRAWGRID (DBGRID1) .row: = row; tdrawgrid (dbgrid1) .col: = col; dbgrid1.setfocus; you can see the effect.

1 This method is absolutely problematic. It will cause chaos inside DBGRID because DBGrid cannot locate the current record. If DBGRID is read, it is still a problem, such as the record that can only be radically only radio. Multi-selection, etc. You can try it yourself). If DBGRID edits, you can be big, because the current record relationship, the data field you change is likely to be the 2 I have a common solution. Change the program to (casually set col is safe, no problem)

Query1.first; tdrawgrid (dbgrid1) .col: = 1; dbgrid1.setfocus;

This allows the focus to move to the first column of the first line.

2003-11-17 14:55:26 How to make the color of the DBGRID grid change with the data value in this grid change? In the interface, sometimes in order to highlight the various characteristics of the data (eg, too much or too small), it is necessary to change the font or color, this article is a description of this situation.

How to make the color of the DBGRID grid changes with the data value in this grid. As the "grid of <60 is red? Data control components DBGRID in Delphi are the most important and most common components for reflecting data sheets. In the application, if DBGRID is displayed in a colorful manner, it will increase its visibility, especially when there are some important or need to be alerted, you can change the rows or columns of the data and the background of the rows and backgrounds. colour. DBGRID Properties DEFAULTDRAWING is used to control Cell (grid) drawing. If DEFAULTDRAWING is set to true, it means that Delphi uses DBGRID's default drawing method to make a grid and the data contained therein, and data is drawn in accordance with the DisplayFormat or EditFormat feature of the TField member connected to a particular column; If DBGRID's defaultdrawing feature is set to false, Delphi does not draw grid or its content, and you must provide your own draw routine (self-drawing function) in TDBGRID's OnDrawDataAsell event. An important attribute that will be used herein: Canvas Canvas, many components have this property. Canvas represents the surface currently displayed DBGRID. If you specify another custom display content and style to the Canvas of the DBGRID object, the DBGRID object will display the Canvas property value on the screen. When applying, it involves the brush attribute of Canvas and the FillRect method and the Textout method. The Brush property specifies the image, color, style, and access to the Windows GDI object handle, and the FillRect method uses the current brush property to populate the rectangular area, and the method TextOut outputs the text content of Canvas. The following examples describe how to display colored DBGRIDs in detail. In the example, there is a DBGRID component, followed by a SpineDit component for generating a color filter condition, and the ColorGrid component is free to select the foreground and background of the data unit.

1. Create a Project called ColordBGrid, put the desired component in turn in its form form1, and set the attribute as the corresponding value, specifically listed below:

Table1 DatabaseName: DBDEMOS TableName: EMPLOYEE.DB Active: True; DataSource1 DataSet: Table1 DBGrid1 DataSource1: DataSource1 DefaultDrawing: False SpinEdit1 Increment: 200 Value: 20000 ColorGrid1 GridOrdering: go16 * 1

2. Write a response program for the DBGRID1 component onDrawDatacell event:

File: // The program written here is the case where the grid is red, the other can push Procedure TFORM1.DBGRID1DRAWDATAC1.DBGRID1DRAWDATAC1.DBGRID1DRAWDATACELL (SENDER: TFIELD: TFIELD; STATE: TGRIDDRAWSTATE); Begin IF Table1.Fieldbyname ( 'Salary') value <= SpinEdit1.value then DBGrid1.Canvas.Brush.Color: = ColorGrid1.ForeGroundColor else DBGrid1.Canvas.Brush.Color: = ColorGrid1.BackGroundColor; DBGrid1.Canvas.FillRect (Rect). DBGrid1.canvas.textout (Rect.Left 2, Rect.top 2, Field.Asstring); END; This process is the role of this process is when the condition given by SpineDit1 is satisfied, such as the 'Salary' variable is lower than or equal to Spinedit1.Value DBGRID1 records in the foreground color of ColorGrid1, otherwise it is displayed in the background color of ColorGrid1. Then call the DBGRID's CANVAS fill process and the text output process to re-draw the DBGRID screen.

3. Write a response code for the onchange event for SpineDit1 components:

Procedure tform1.spinedit1change (sender: TOBJECT); begin dbgrid1.refresh; file: // Refresh is required, be refreshed, End;

Refresh DBGRID1 when the value of the SpineDit1 member changes.

4. Write a response code for the onchange event of ColorGrid1:

Procedure tform1.colorgrid1change (sender: TOBJECT); begin dbgrid1.refresh; file: // Refresh is required, be refreshed, End;

When the value of ColorGrid1 changes, the right button or left mouse button of the mouse is re-refreshed with the ColorGrid1.

5. Write a response code for the oncreate event of the Form1 form (main form):

Procedure TFORM1.FormCreate (Sender: TOBJECT); Begin Colorgrid1.ForeGroundIndIndex: = 9; ColorGrid1.BackgroundIndex: = 15;

When you create the main window, set the initial value of ColorGrid1 as gray, the background is white, that is, the font color of DBGrid is gray, background color is white.

6. Now you can compile and run the ColordBGRID program. When using the left button or right-click ColorGrid1, the font and background color of the DBGRID will change.

In this article, it is simply shown that the principle of displaying DBGRID in color is displayed. Of course, it can also increase the complexity of the program so that it is actually used. The same truth, you can also extend this method to other components with the Canvas property, allowing the application's user interface more friendly.

2003-11-17 14:58:08 Judging whether Grid has a scroll bar? This is a tip, if it is a unified words for the style, don't use it. :)

. . .

if (GetWindowlong (Stringgrid1.Handle, GWL_STYLE) and WS_VSCROLL) <> 0 then ShowMessage ( 'Vertical scrollbar is visible!'); if (GetWindowlong (Stringgrid1.Handle, GWL_STYLE) and WS_HSCROLL) <> 0 then ShowMessage ( 'Horizontal scrollbar IS Visible! ') ;. . .

2003-11-17 15:04:27 Synchronous scrolling of two grids in actually making a project, sometimes a few Grid will synchronize scrolling to reduce the user's operation. I hope that the code below has a certain reference value.

{1.}

Unit syncstringgrid;

Interface

Uses Windows, Messages, Sysutils, Classes, Graphics, Controls, Forms, Dialogs, Grids

TYPE TSYNCKIND = (Skboth, Skvscroll, Skhscroll); TsyncStringGrid = Class (TstringGrid)

private FInSync: Boolean; FsyncGrid: TSyncStringGrid; FSyncKind: TSyncKind; {Private declarations} procedure WMVScroll (var Msg: TMessage); message WM_VSCROLL; procedure WMHScroll (var Msg: TMessage); message WM_HSCROLL;

protected {protected declarations}

Public {public declarations}.

Published {published Declarations}}} tycgrid: TsyncStringGrid Read FsyncGrid Write FsyncGrid; Property Synckind: Tsynck Ind Read Fsynckind Write Fsynck IndiaNCKIND WRITE FSYNCKIND Default Skboth;

PROCEDURE register;

IMPLEMentation

Procedure Register; Begin RegisterComponents ('Samples', [TsyncStringGrid]); END;

procedure TSyncStringGrid.WMVScroll (var Msg: TMessage); begin if not FInSync and Assigned (FSyncGrid) and (FSyncKind in [skBoth, skVScroll]) then FSyncGrid.DoSync (WM_VSCROLL, Msg.wParam, Msg.lParam); inherited; end;

procedure TSyncStringGrid.WMHScroll (var Msg: TMessage); begin if not FInSync and Assigned (FSyncGrid) and (FSyncKind in [skBoth, skHScroll]) then FSyncGrid.DoSync (WM_HSCROLL, Msg.wParam, Msg.lParam); inherited; end;

Procedure TsyncStringGrid.dosync (MSG, WPARAM: Integer; LParam: longint); begin Finsync: = true; Perform (MSG, WPARAM, LPARAM); FINSYNC: = FALSE; END; END.

{**************************************}

{2.} private oldgridproc1, oldgridproc2: twndmethod; procedure grid1windowproc (var message: tMessage); Procedure Grid2WindowProc (Var Message: tMessage);

PUBLIC {...}

Procedure TFORM1.GRID1WINDOWPROC (VAR Message: tMessage);

Begin OldgridProc1 (Message); IF ((Message.msg = WM_VScroll) or Message.msg = WM_Mousewheel) The begin OldgridProc2 (MESSAGE); END;

procedure TForm1.Grid2WindowProc (var Message: TMessage); begin OldGridProc2 (Message); if ((Message.Msg = WM_VSCROLL) or (Message.Msg = WM_HSCROLL) or (Message.msg = WM_Mousewheel)) then begin OldGridProc1 (Message); END;

procedure TForm1.FormCreate (Sender: TObject); begin OldGridProc1: = StringGrid1.WindowProc; OldGridProc2: = StringGrid2.WindowProc; StringGrid1.WindowProc: = Grid1WindowProc; StringGrid2.WindowProc: = Grid2WindowProc; end;

2003-11-19 9:35:04 In Delphi, the color of the DBGRID will use the DBGRID control in Delphi. Each column can change the color as needed, but it is difficult to change the color of each line. So without re-reproducing new controls, there is no good way to let DBGRID change each line color according to the user yourself. The answer is yes, and a simple method is introduced below.

To change the color of each line of DBGRID, as long as you want to change the crow of colors in the OnDrawColumnCell event, and specify the canvas.brush.color property of DBGRID and set the canvas.pen.mode property into pmmask, then call DBGRID's defaultdrawColumnCell Method can be. Note that before changing these two properties, you must first protect the value of the original canvas.brush.color property. After the regulator is completed, the original attribute value is changed back, now in the Delphi / DMOS / DB / ClientMD directory. The program clintproj.dpr is an example, which is a brief description. Here is a colors that disconnects the combined parts of the grid membergrid in the program, becomes a black, other non-conditional rows of colors for normal fonts, white backgrounds, other conditions provided only in the constant DrawColumnCelL event, as follows: procedure TClientForm.MemberGridDrawColumnCell (Sender: TObject; const Rect: TRect; DataCol: Integer; Column: TColumn; State: TGridDrawState); var oldcolor: tcolor; oldpm: tpenmode; begin if DM.ProjectTEAM_LEADER.Value = DM.Emp_ProjEMP_NO.Value then {sets the row discoloration condition} MemberGrid.Canvas.Font.Style: = [fsBold]; MemberGrid.DefaultDrawColumnCell (Rect, DataCol, Column, State); { The above is the original content of the demonstration program, the following is increasing part} if DM.ProjectTeam_leader.Value = DM.EMP_PROJEMP_NO.VALUE THEN {Settings Conditions} Begin Oldpm: = Membergrid.canvas.Pen.Mode; OldColor: = MemberGrid.Canvas.Brush.color; MemberGrid.Canvas.Brush.color: = clyellow; MemberGrid.Canvas.pen.mode: = pmmask; MemberGrid.DefaultDrawColumnCell (Rect, DataCol, Column, State); MemberGrid.Canvas.Brush.color : = OldColor; MemberGrid.canvas.pen.mode: = OLDPM; END; END; It feels the same as the principle of several color control methods in front of this method, which is the ability to achieve color-stroning. :)

2003-11-19 9:43:56 How to support multiple records in dbgrid This document comes from abroad, it is very useful, it is useful, it is recommended to learn to use. [Question]: How to do multi-selecting records in TDBGrid When you add [dgMultiSelect] to the Options property of a DBGrid, you give yourself the ability to select multiple records within the grid The records you select are represented as bookmarks and?. are stored in the SelectedRows property The SelectedRows property is an object of type TBookmarkList The properties and methods are described below.// property SelectedRows:.. TBookmarkList read FBookmarks;

// TBookmarkList = class // public {* The Clear method will free all the selected records within the DBGrid *} // procedure Clear; {* The Delete method will delete all the selected rows from the dataset *} // procedure Delete; {* The Find method determines whether a bookmark is in the selected list *.} // function Find (const Item: TBookmarkStr; // var index: Integer): Boolean; {* The IndexOf method returns the index of the bookmark within the . Items property *} // function IndexOf (const Item: TBookmarkStr): Integer; {* The Refresh method returns a boolean value to notify whether any orphans were dropped (deleted) during the time the record has been selected in the grid The. refresh method can be used to update the selected list to minimize the possibility of accessing a deleted record *} // function Refresh:. Boolean; True = orphans found {* The Count property returns the number of currently selected items in the DBGrid *}// property Count: Integer read GetCount; {* The CurrentRowSelected property returns a boolean value and determines whether the current row is selected or not *.} // property CurrentRowSelected: Boolean // read GetCurrentRowSelected // write SetCurrentRowSelected; {* The Items Property is a tstringlist of tbookmarkstr *} // Property items [index: integer]: tbookmarkstr // read GetItem; default; // end; unit unit1;

Interface

Uses Windows, Messages, Sysutils, Classes, Graphics, Controls, Forms, Dialogs, Stdctrls, Grids, DBGRIDS, DB, DBTABLES

type TForm1 = class (TForm) Table1: TTable; DBGrid1: TDBGrid; Count: TButton; Selected: TButton; Clear: TButton; Delete: TButton; Select: TButton; GetBookMark: TButton; Find: TButton; FreeBookmark: TButton; DataSource1: TDataSource ; procedure countClick (Sender: TObject); procedure SelectedClick (Sender: TObject); procedure ClearClick (Sender: TObject); procedure DeleteClick (Sender: TObject); procedure SelectClick (Sender: TObject); procedure GetBookMarkClick (Sender: TObject); procedure FindClick (Sender: TObject); procedure FreeBookmarkClick (Sender: TObject); private {Private declarations} public {public declarations} end; var Form1: TForm1; Bookmark1: TBookmark; z: Integer;

IMPLEMentation

{$ R * .dfm}

file: // Example of the Count propertyprocedure TForm1.CountClick (Sender: TObject); begin if DBgrid1.SelectedRows.Count> 0 then begin showmessage (inttostr (DBgrid1.SelectedRows.Count)); end; end;

file: // Example of the CurrentRowSelected propertyprocedure TForm1.SelectedClick (Sender: TObject); begin if DBgrid1.SelectedRows.CurrentRowSelected then showmessage ( 'Selected'); end;

File: // eXample of the clear methodprocedure tform1.clearclick (sender: TOBJECT); begin dbgrid1.selectedRows.clear;

File: // Example of the delete methodProcedure TFORM1.DELETECLICK (Sender: TOBJECT); begin dbgrid1.selectedRows.delete;

{* This example iterates through the selected rows of the grid and displays the second field of the dataset. The Method DisableControls is used so that the DBGrid will not update when the dataset is changed. The last position of the dataset is saved as a TBookmark . The IndexOf method is called to check whether or not the bookmark is still existent The decision of using the IndexOf method rather than the Refresh method should be determined by the specific application *} procedure TForm1.SelectClick.. (Sender: TObject); var x: word; TempBookmark: TBookMark; begin DBGrid1.Datasource.Dataset.DisableControls; with DBgrid1.SelectedRows do if Count> 0 then begin TempBookmark: = DBGrid1.Datasource.Dataset.GetBookmark; for x: = 0 to Count - 1 do begin IF indexof (items [x])> -1 the begin dbgrid1.datasource.DataSet.bookmark: = items [x]; showMessage (dbgrid1.datasource.DataSet.fields [1] .sstring); end; end; end; dbgrid1 .Datasource.dataset.gotobookm Ark (TempBookmark; dbgrid1.datasource.dataset.freebook); dbgrid1.datasource.DataSet.enableControls;

{* This Example Allows you to set a bookmark and and then search for the bookmarked record for the bookmarked record with the dbgrid. *}

File: // sets a bookmarkprocedure TFORM1.GETBOOKMARKCLICK (Sender: TOBJECT); Begin Bookmark1: = dbgrid1.datasource.DataSet.getBookmark; End;

file: // Frees the bookmarkprocedure TForm1.FreeBookmarkClick (Sender: TObject); begin if assigned (Bookmark1) then begin DBGrid1.Datasource.Dataset.FreeBookmark (Bookmark1); Bookmark1: = nil; end; end;

file: // Uses the Find method to locate the position of the bookmarked record within the selected list in the DBGridprocedure TForm1.FindClick (Sender: TObject); begin if assigned (Bookmark1) then begin if DBGrid1.SelectedRows.Find (TBookMarkStr (Bookmark1 ), z) The showMessage (INTSTR (Z)); end; end; end.

2003-11-19 10:11:21 Another way to control DBGRID in Delphi is a problem with DBGRID in Delphi, how to make each line of color in DBGRID according to the user's own wishes . When I first saw this problem, we thought it was very simple, so I immediately prepared to solve it. As a result, it was found that it was not that case, and the traditional method could not work. I have been sitting at 4 am in front of the computer, constantly debugging, fortunately, with a point of programming experience that usually accumulate, I finally found the key key of opening the door. Now it is fully charged for everyone to enjoy.

1. The establishment of the data sheet is selected in the Delphi tool menu, and a data sheet named Example.db is created under the database DBDemos. The fields and contents of the data sheet are as follows: Name Age Wage Zhangshan 25 500 Wang Wu 57 1060 Li City 30 520 Liu Niu 28 390

2. Create a TCOLoredDBGRID component based on TDBGRID in the Delphi component menu, select New Component, make the following settings in the pop-up dialog:

Annestor type = tdbgridclass name = tcoloreddbgrid

Then click the OK button, Delphi automatically completes the definition of the basic framework of the component. Add an OnDrawColoredDBGRID event and make it appear in the Events of the Object Inspector to set the conditions for changing the colors in the application. Heavy duty Drawcell method can only draw units themselves. You cannot set the color by OnDrawColumncell, because the color of the onDrawColumncell change cell will again trigger OnDrawColumncell again. Below is the source program of the created component.

3. Establish an application to verify. Select NEW to create new application engineering Project1 and main forms FORM1 in the Delphi file menu, set the Form1's CAPTION attribute to "Controlling the DBGRID Color Color." Add Data Source, Table, Button, and ColoredDbGrid components on the main form. Setting the properties of each component as follows:

Table1.Database = 'dbdemos'table1.tablename =' example.db'dataroup1.dataset = table1coloreddbgrid1.datasource = Datasource1Button1.caption = 'Exit'

Enter the following code in the COLOREDDBGRIDDDDBGRID event, set by WAGE to determine the color of the coloreddbgrid1.

procedure TForm1.ColoredDBGrid1 DRawColoredDBGrid (Sender: TObject; Field: TField; var Color: TColor; var Font: TFont); Var p: Integer; begin p: = Table1.FindField ( 'wage') AsInteger; file:. // obtain The value of the currently recorded WAGE field. IF (P <500) The begin file: // The program will set the color of each row according to the WAGE value. Color: = CLGreen; font.style: = [fness: // can not only change the color, but also change the font end; if (p> = 500) AND (P <800) Then Color: = CLRED; if (IF) P> = 800) The begin color: = clmaroon; font.style: = [fsbold]; end; end; file: // End the program with the 'exit' button. Procedure TForm1.Button1Click (Sender: TOBJECT); Begin Close; End; 2003-11-19 10:16:11 Displaying Multi-Data Logs in Database Programming, unnecessaries are not possible to operate all database fields Put in a database file. The correct database structure should be: put the database field into multiple database files, and the relevant database contains a unique key field that can be set in the multi-database structure. For example: To prepare a personnel management program, to simplify the demo, only two databases, each database only established two fields. Personal Profile Jianjie.dbf 1. The establishment of the database enters Database Desktop, the establishment of the database structure is as follows: jianjie.dbf number field name: Bianhao Size: 4 TYPE: Number Name Field Name: Xingming Size: 10 Type: Character

Gongzi.dbf number field name: Bianhao Size: 4 TYPE: Number salary field name: gongzi size: 4 DEC 2 TYPE: NUMBER

Note: The size, TYPE of the Bianhao field of the two databases must be consistent. In fact, the two database files can be distributed on different computers of the network to facilitate demonstrations, respectively, to "c: /test/jianjie.dbf" and "c: /test/gongzi.dbf", respectively.

2. The application of the application launches Delphi, create a new project, add the Query control query11 in the form, and the DatabaseName property is set to C: / Test;

Join the DataSource control DataSource1, the DataSet property is set to query1; join the DBGRID control DBGRID1, the DataSource property is set to DataSource1, set the query1.sql attribute to

Select Distinct A.Bianhao, A.xingming, B.Gongzi from "jianjie.dbf" a, "gongzi.dbf" b where A.bianhao = B.Bianhao

Then set the query1.enabled attribute to True, do not compile, DBGRID1 will display: bianhao, xingming, gongzi three fields. If there is record in jianjie.dbf and gongzi.dbf, the record will be displayed. Because of the boundary, this article only introduces the general method of displaying multiple database contents in DBGRID, readers can improve on this, so that this method can better adapt to your needs. 2003-11-19 10:19:40 How to make the carriage return in DBGRID to the right movement in the Form.onkeyPress event is written in the form:

IF key = # 13 Then if ActiveControl = dbgrid1 the begin TdbGrid (activeControl) .SelectedIndex: = TDBGRID (ActiveControl) .selectedIndex 1; Key: = # 0;

There are 2 points to pay attention: 1. When the cursor reaches the rightmost right column, press Enter, the cursor will stay in place. 2.Key: = # 0

2003-11-19 10:25:07 Record from DBGRID Procedure TFORM1.DBGRID1DBLCLICK (Sender: Tobject); VAR x: Integer; Hadtoopen: Boolean; Begin with sender as tdbgrid do beg, hadtoopen: = NOT TTARGET.ACTIVE; if Hadtoopen dam; ttatget.Append; for x: = 0 to Fieldcount - 1 do case fields [x] .DataType of ftboolean: Ttarget.fieldbyname (fields [x] .fieldname) .asboolean: = fields [ x] .asboolean ftstring: Ttarget.fieldbyName (fields [x] .fieldname) .sstring: = fields [x] .sstring ftfloat: Ttarget.fieldbyName (fields [x] .fieldname) .asfloat: = FIELDS [x] .asfloat ftinteger: Ttarget.fieldByname (Fields [x] .fieldname) .asinteger: = Fields [x] .asinteger ftdate: Ttarget.fieldbyName (Fields [x] .fieldname) .asdatetime: = FIELDS [x] .asdatetime; end; ttarget .Post; if Hadtoopen kilnTtarget.active: = false;

2003-11-19 10:27:58 Using DBGRID's check item (please refer to how to support multiple records in DBGRID) Procedure TForm1.SelectClick (Sender: Tobject); var x: word; tempbookmark: tbookmark; begin DBGrid1.Datasource.Dataset.DisableControls; with DBgrid1.SelectedRows do if Count <> 0 then begin TempBookmark: = DBGrid1.Datasource.Dataset.GetBookmark; for x: = 0 to Count - 1 do begin if IndexOf (Items [x]) > -1 then begin DBGrid1.Datasource.Dataset.Bookmark: = Items [x]; showmessage (DBGrid1.Datasource.Dataset.Fields [1] .AsString); end; end; end; DBGrid1.Datasource.Dataset.GotoBookmark (TempBookmark ); Dbgrid1.datasource.dataset.freebook; dbgrid1.datasource.DataSet.EnableControls; end; 2003-11-19 10:32:27 Drag & Drop on dBGRID Drag & Drop) We found in the program, If the user can drag and drop one Edit's content directly into a dbgrid, it will be very convenient, but found in the programming process, it seems to drag and drop to the current record, if you want to drag and drop to other What should I do, I can't let the user choose to record, then drag and drop. Later, through the study, when using the mouse point DBGRID, DBGRID will automatically move the record pointer to the recorded record, which gives me a thinking, let the program simulate a click on DBGRID to let the cursor move to On the record, you can write the drag and dropped data into the dbgrid. Through the fact that this idea is feasible. Below, I will tell you that my approach: 1) First put a dbgrid on Form, and it can display records, (this is relatively simple, don't say more) 2) Playing an edit 3 on Form 3) Modify Edit Attribute, change DragMode to DMAUTOMATIC, allowing users to drag and drop 4) Add the following code in DBGRID Dragover event: Let it receive Drag & Drop

Procedure tForm1.dbgrid1dragover (Sender, Source: Tobject; x, y: integer; state: tdragState; var accept: boolean; begin accept: = true;

5) Add the following code in the DBGRID DragDrop event: Let it automatically jump to the record specified by the cursor

procedure TForm1.DBGrid1DragDrop (Sender, Source: TObject; X, Y: Integer); begin if Source <> Edit1 then exit; with Sender as TDbGrid do begin Perform (wm_LButtonDown, 0, MakeLong (x, y)); PerForm (WM_LButtonUp , Makelong (x, y); selectedfield.dataset.edit; selectdfield.Asstring: = Edit1.Text; end; end; to this, we have achieved the desired function, where Perform is a general method purpose of TControl It is a message loop bypassing the Windows itself, and the message sent directly to the contract, please refer to Delphi's help.

2003-11-19 10:39:19 How to make DBGRID's pointer? [Question]: I use DBGRID to display the contents in Table, now I want to read the data in Table from the head to the end, with table1.first, next to make the pointer in DBGRID also followed, how can I make this time DBGRID? The pointer inside does not move?

[Answer]: Use the following code:

WITH DATASET DO TRY DISABLECONTROLS; DO_SMETHING; FINALLY EnableControls;

2003-11-19 10:42:14 How to dynamically update the color of DBGRID? (Please refer to "How to make the color of the DBGRID grid change with the data value in this grid?") DBGRID control is a control of the display database with many user interfaces. The following programs tell you how to display content Change the display color of the font. For example, if the population of a city is greater than 2 million, we let it show blue. The control event used is DBGrid.ondrawColumecell.

procedure TForm1.DBGrid1DrawColumnCell (Sender: TObject; const Rect: TRect; DataCol: Integer; Column: TColumn; State: TGridDrawState); begin if Table1.FieldByName ( 'Population') AsInteger> 20000000 then DBGrid1.Canvas.Font.Color.: = CLBLUE; DBGRID1.DEFAULTDRAWCOLUMNCELL (Rect, Datacol, Column, State);

The above example is simple, but you can expand according to your own needs, such as the font also change, etc., or even call the drawn function to draw a red circle on the number.

2003-11-19 10:45:14 Use the DBGRID display Date when using the DBGRID control, its year is 2 digits, but we need to display the date after step into 2000, such as: 1998, 2001. In the database, only 4 digits will be displayed after 2000. What should I do? Let's let this field also display 4 digits in the DBGRID control: Double-click the Table1 control, there will be a Form1.Table form, right click, select Add Fields ..., select the date field, press OK, Form There is a date field name of the database. The field name of the point date is displayed. There is an information on this field in the Properties box, and there is a DispalyFormat, enter YYYY.MM.DD in this display format, then DBGRID control appears A complete date. 2003-11-19 10:48:37 Implement another idea to drag and drop in the TDBGRID control (please refer to DRAG & DROP on DBGRID) in this unit, custom TMYCUSTOMDBGRID = Class (TCUSTOMDBGRID), References as follows:

TMYCUSTOMDBGRID (DBGRID1) .MOUsedown (...) or dBGRID1 AS TMYCUSTOMDBGRID) .MOUsedown (...).

2003-11-19 10:56:11 How to set up the Enter key in the DBGRID table is equivalent to single click? [Routines]: Place Table1, DataSource1, DBGRID1, set the connection between Table1, DataSource1, DBGRID1, set the connection between DBGRID1. Then: Procedure TFORM1.DBGRID1KEYPRESS (Sender: Tobject; Var Key: char); begin with dbgrid1 do if key = # 13 death DBGRID1CELLCLICK (Columns [SELECTEDEX]); END;

Procedure tForm1.dbgrid1cellclick (Column: tcolumn); begin with dbgrid1 do showmessage (format ('row =% d', [selectedIndex]);

2003-11-19 11:07:55 Delphi's drop-down list and find field programming method data grid is a very popular data entry and display form, like everyone familiar with Excel, powerful brows, etc. in VFP, etc. For the majority of programmers. When using the Delphi development database application system, use the data grid DBGRID to enter the data, some fields only allow for a few fixed strings, such as the storage period of the archives, only "permanent", "long-term" and "short-term" three Can you choose from a drop-down list, which is convenient to input and avoid input errors? There are also some fields, such as unit numbers in the employee information library (more detailed information in additional unit libraries), when entering and displaying employee data, can be operated without the unit number, alternative to more intuitive What about the unit name in the unit library? The answer is affirmative, Delphi's data grid control DBGRID, supports the drop-down list and finding the field programming, and the programmed process is visual, and does not need to write a row statement.

First, the drop-down list in DBGRID implements a drop-down list in the DBGRID grid, sets a list of Picklist strings in DBGRID, and the initial number value DropDownRows can be used. 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: - ------------------------------------- Object property set value -------- ------------------------------- Table1 Database Sy1 Table Zgk.dbf file: // Staff Information Database 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 "Hubei Zhijiang City (Renewal) Beijing (Renewal) Henan Pingdingshan City (Renewal) Zhejiang Deqing City

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 lookup field in DBGRID The so-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 from another database table - unit library, called "unit number" Field. 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 Table Zgk.dbf file: // Staff Information Library Table2 Database Sy1 Table DWK.DBF File : // Unit Information Database Datasource1 Dataset Table1dbGrid1 Datasource 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 all the fields are selected, 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 a 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.

Announced to http://www.lihuasoft.net/article/show.php?id=874

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

New Post(0)