Delphi provides a powerful DBGrid component to facilitate database application design. But if we just use the DBGrid component, each gain focus (Grid) is just a simple text edit box, which makes it inconvenient for users to enter data. Delphi also provides a number of other data components to facilitate user input, such as dbcombobox,dbcheckbox and other components, but these components are not dbgrid powerful. Can Delphi, like Visual FoxPro, get the focus grid in DBGrid to be other visual data components for the convenience of the user? We can actually do this by inserting other visual components into the DBGrid.
The internal mechanism of Delphi processing for DBGrid is to float a component--dbedit component on the grid. The grid in which you enter the data is actually a floating dbedit component, and other places that don't get focus are just images. So, inserting other visual components in DBGrid is a visual component floating on the grid. So any component, including from simple Dbcheckbox to complex dialog boxes, can be inserted into the DBGrid. Here's how to insert a Dbcombobox component in a DBGrid, using the same approach to insert other components.
1, a new project in Delphi 4.0.
2. Drag the Data Access palette on the DataSource, Table,data controls component Board Dbgrid,dbcombobox four components to the FORM1.
3, set the properties of each component as follows:
properties |
set-sik |
caption |
insert Spinedit Component sample |
dataset |
table1 |
tab Le1 |
dbdemos |
|
tablename |
teacher. DBF |
|
active |
true |
data Source |
datasource1 |
dbcombobox1 |
datafield |
SEX | /tr>
|
datasource |
datasource1 |
|
visi ble |
|
strings Items. |
" > male | female |
Note: I used the teacher.dbf here, that reflects the staff's gender, can only be "male" or "female".