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; 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 Then 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 Hide or Display Title Bar DBGRID Control Hide or Display Title Bar 1, Newly Build Procedures with Two Parameters (The 1st Parameters are menu objects, the second is DBGRID control : Procedure ViewTitle (Sender: Tobject; DBGCOLUMNS: TDBGRID); // Hide or Display 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, the sub-menu The TAG of the item is set to correspond to the COLUMNS value of DBGRID, such as the dbgrid has a title bar is 'date' at the 0 column, and then sets 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; end; If you need to let him keep roll from beginning to tail, add The following code If Table1.eOf the table1.first; two design comparisons with DBGRID, DBGRID, Dash-down list, implements drop-down list in the DBGRID grid, set a list of Picklist strings in DBGRID, initial The serial 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: - ------------------------------------- Object property set value -------- ------------------------------ Table1 Database Sy1 Tablename ZGK.DBF // Staff DataSource1 Dataset Table1dbGrid1 DataSource Datasource1dbnavigator1 DataSource Datasource1 ------------------------------------------ 2, double click on Table1, in the pop-up In the 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. 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 Deqing City, Peking, Hubei City, Beijing, China" 6, write in the Form1.oncreate event Into the statement: 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, which contains the four lines of strings entered on step 5. You can choose from 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.