Use of DBGrid controls in the Visual C + + Environment

Source: Internet
Author: User

DBGrid data Table control with its short and popular, but how it is used in Visual C + + but rarely an article mentioned, this article will be VC under the specific steps to use DBGrid briefly introduced to everyone.

I. Pre-preparation

In order to implement the automatic binding of the DBGrid control, we need to establish a database and associated data source, in this case we use access to build the database Mydata.mdb, create a new table in the database users, including three fields username,address, email, and enter more than one record.

Create a System DSN named Test in the Control Panel ODBC data source and point it to Mydata.mdb

Two. Create the project

Create a new MFC AppWizard (EXE) project based on the dialog box, named Gridtest, and AppWizard

Confirm that ActiveX control support has been provided in step 2nd of the.

Three. Inserting controls

We need to insert the Microsoft RemoteData Control and DBGrid two controls with the following methods:

1 Select menu->project->add to Project->components and Controls Gallery

2 Enter registered ActiveX Controls in the Part selection dialog box

3 Select Microsoft RemoteData Control, click the Insert button, and confirm the configuration of the class (You can press

Default), we do not make any changes click OK button, insert complete.

In the same step, insert the DBGrid control.

4 Back to the VC workspace, we select the Gridtest dialog template in ResourceView (that is, the dialog template with ID number Idd_gridtest_dialog) we found two buttons already added to the controls sidebar. Represents the two controls that were just inserted.

5 Now we draw the two controls in the template, as shown in the figure:

Four. Change control properties

Right-click the RemoteData control, select Properties in the right-click menu, and eject the property dialog box,

In the Control tab, select Data Source test, and enter SQL statements in SQL for example: SELECT * from Users

As shown in the following illustration:

In the same way we open the Properties dialog box for the DBGrid control.

Click the All tab to select the ID number of RemoteData control in the DataSource entry: IDC_REMOTEDATACTL1,

As shown in the following illustration:

The entire program has been completed, we can compile and run to see how the effect! It is worth noting that access should be closed before running, otherwise the database will not be accessible.

This paper introduces the basic use of DBGrid control in detail, and other forms of control can also refer to this process, hoping to enlighten everyone.

Environment: Visual c++6.0, Windows98

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.