关于dbgrid的问题!师傅请进!!

qinxiaojie1978 2003-09-28 09:45:02
第一个问题:如何,使其的picklist,,显示数据库中具有相同标识的记录,我只能数据控件把所有记录显示出来。
第二个问题:如何,使 picklist 显示的是另一个表的某一描述字段的记录,当修改提交的时候,写入当前表的是另一个表的记录的另一个标识字段的值。
请给与答复,!!!!
...全文
61 8 打赏 收藏 转发到动态 举报
写回复
用AI写文章
8 条回复
切换为时间正序
请发表友善的回复…
发表回复
qinxiaojie1978 2003-09-28
  • 打赏
  • 举报
回复
好了,问题自己解决了,谢谢师傅们
qinxiaojie1978 2003-09-28
  • 打赏
  • 举报
回复
第一个问题,我解决了,第二个,怎么操作阿,,,,wwDbGrid这个控件没有用过!!从哪下载一个用??
pilicat 2003-09-28
  • 打赏
  • 举报
回复
非常抱歉,我看错了,答非所问了!
pilicat 2003-09-28
  • 打赏
  • 举报
回复
用一个Timer控件,每隔一秒钟检查一次数据库连接状态,如果连接已经断开,则重新连接,示例代码:

if not database1.connected then
//在这里写重新连接的代码!
rust 2003-09-28
  • 打赏
  • 举报
回复
佩服楼上的,不过我想楼主不会仔细看的,至少我没看!
IORILI 2003-09-28
  • 打赏
  • 举报
回复
This topic covers providing values to a column using a picklist to enter a new value to a column, and it also covers creating a lookup that will display values from another column.

Tutorial: Data entry with a picklist
This tutorial shows how to create a picklist that can be used to set the value of the JOB_COUNTRY column from the list of countries available in the COUNTRY table. When the user selects a country from the picklist, that selection is automatically written into the current field of the table. This project can be viewed as a completed application by running the sample project Picklist.jpx, located in the /samples/DataExpress/Picklist subdirectory of your JBuilder installation.

This application is primarily created in the designer.


Select File|New Project.

Enter a name and location for the project in the Project Wizard. Click Finish.

Select File|New from the menu. Double-click the Application icon.

Specify the package name and class name in the Application Wizard. Click Finish.

Select the Design tab to activate the UI designer.

Click the Database component on the Data Express tab of the component palette, then click in the Structure pane to add the component to the application.

Open the connection property editor for the Database component by selecting, then double-clicking the connection property ellipsis in the Inspector. Set the connection properties to the JDataStore sample employee table as follows. The Connection URL points to a specific installation location. If you have installed JBuilder to a different directory, point to the correct location for your installation. Property name Value
Driver com.borland.datastore.jdbc.DataStoreDriver
URL jdbc:borland:dslocal:/usr/local/jbuilder/samples/JDataStore/ datastores/employee.jds
The employee.jds database is located under the samples directory of your JBuilder installation, which may be different on your system. This sample has been modified to find the file on your system.

Username Enter your name
Password not required


The connection dialog includes a Test Connection button. Click this button to check that the connection properties have been correctly set. Results of the connection attempt are displayed in the status area. When the connection is successful, click OK.


Add a QueryDataSet component to the designer by clicking on the QueryDataSet component on the Data Express tab and then clicking in the Structure pane.
Select the query property of the QueryDataSet component in the Inspector, double-click its ellipsis to open the QueryDescriptor dialog, and set the following properties: Property name Value
Database database1
SQL Statement SELECT * FROM EMPLOYEE


Click Test Query to ensure that the query is runnable. When the status area indicates Success, click OK to close the dialog.


Select a DBDisposeMonitor component from the More dbSwing tab. Click in the Structure pane to add it to the application. The DBDisposeMonitor will close the JDataStore when the window is closed.

Set the DBDisposeMonitor's dataAwareComponentContainer property to this.
To view the data in your application we need to add some UI components and bind them to the data set. To do this,


Select contentPane(BorderLayout) in the Structure pane. In the Inspector, set its layout property to null.

Select a JdbNavToolBar component from the dbSwing tab. Drop the component in the area slightly above the panel in the Design frame. JdbNavToolBar automatically attaches itself to whichever DataSet has focus, so you do not need to set its dataSet property.
The JdbNavToolBar will enable you to move quickly through the data set when the application is running, as well as provide a default mechanism for saving changes back to your data source.



Click on the JdbStatusLabel component on the dbSwing tab of the component palette. Drop the component in the area slightly below the panel in the Design pane. JdbStatusLabel automatically attaches itself to whichever DataSet has focus, so you do not need to set its dataSet property.
Among other information, the status label displays information about the current record or current operation.



Add a TableScrollPane component from the dbSwing tab to the designer.
Scrolling behavior is not available by default in any Swing component or dbSwing extension, so, to get scrolling behavior, we add the scrollable Swing or dbSwing components to a JScrollPane or a TableScrollPane. TableScrollPane provides special capabilities to JdbTable over JScrollPane. See the dbSwing documentation for more information.


Drop a JdbTable component from the dbSwing tab into the TableScrollPane component. Set its dataSet property to queryDataSet1.
You'll notice that the designer displays live data at this point.


To add the picklist functionality,

Add another QueryDataSet component from the Data Express tab of the palette to the Structure pane. This will form the query to populate the list of choices. Set the query property of queryDataSet2 as follows: For this option Make this choice

--------------------------------------------------------------------------------

Database database1
SQL Statement select COUNTRY from COUNTRY

Click Test Query. When successful, click OK.


Click the expand glyph to the left of the queryDataSet1 component in the Structure pane to expose all of the columns. Select JOB_COUNTRY.

Open the pickList property editor in the Inspector to bring up the pickListDescriptor. Set the pickList properties as follows: Property name Value
Picklist/Lookup DataSet queryDataSet2
queryDataSet2 COUNTRY
Data Type STRING
Show in picklist checked
queryDataSet1 JOB_COUNTRY

Click OK.


Click the source tab. Enter the following code after the call to jbInit(). This opens queryDataSet2, which is attached to the COUNTRY table. Normally, a visual, data-aware component such as JdbTable would open the data set for you automatically, but in this case, there is no visual component attached to this data set, so it must be opened explicitly.

queryDataSet2.open();


Run the application by selecting Run|Run Project.
Click the Insert button on the toolbar. Enter a new record, using the picklist to enter the value for JOB_COUNTRY. When the application is running, you can insert a row into the table, and, when it you enter a value for the JOB_COUNTRY field, you can select it from the drop-down pick list. The country you select is automatically inserted into the JOB_COUNTRY field in the EMPLOYEE data set.


Removing a picklist field
To remove a picklist,


Select the column that contains the picklist in the Structure pane.
Open the pickListDescriptor dialog by clicking in the pickList property in the Inspector.
Set the PickList/Lookup DataSet field to <none>.
IORILI 2003-09-28
  • 打赏
  • 举报
回复
up
tong_jin 2003-09-28
  • 打赏
  • 举报
回复
你使用infoPower控件吧 wwDbGrid比较好用,可以直接把DbcomboBox嵌入Dbgrid

5,386

社区成员

发帖
与我相关
我的任务
社区描述
Delphi 开发及应用
社区管理员
  • VCL组件开发及应用社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧