ATL Tree Control and OLE DB

This small example is for the beginner who wants to create an ActiveX control by superclassing the windows common control using ATL 3.0. If you don't have VC6, you need to install OLE DB1.1 from VC5 for this project to work properly.

On this site, a lot of excellent examples about tree controls are already there so why this example? Because:

  1. My tree control create by using ATL instead of MFC
  2. Using OLD DB to save tree structure and load it back
  3. Right click to open popup menu and more...
The main reason I want to post my article is because I am using OLE DB and OLE DB is still new to some programmers, especially for a new beginner.

Before you use this article, you should have Access database to see OLE DB in action. If you don't have Access database but you have another database like Oracle, SQLServer or SQL Anywhere and you want to know how to do it is beyond the scope of this article.

Open Access database and create a table, and name it any name as you like. Create four fields in the table with the names as follow:

  • ITEM_NODE ( int )

  • ITEM_NAME ( text )

  • INDENT_LEVEL ( int )

  • ITEM_DATA ( long ) [ primary key ]

if you want to create some bogus data, go head and do it, otherwise the example will create default data for you. If you don't want to use any database at all, two things you need to do:

  1. Open your project, click on FileView tab, remove the file name: Tree.h
  2. Open MyTreeControl.h, go to the method name " OnDestroy() " and comment out the line: " this->SaveTree(); ", after all select Build on the menu and select Rebuild All.

When the project is running, the first thing you need to do is select " Microsoft Jet 3.51 OLE DB Provider ( if you have another OLE DB Provider on your system, go head and select it. ", second is select your data source. If you don't have any data in your table yet, just click cancel when the dialog asking you to select a driver and you will have the default data which I created for you.

To test this control, You can select the ActiveX Control test container to test it or you can create a new MFC project with Dialog base. When the project is completely constructed, click on Resource View, open Dialog resource, right click on dialog and select insert ActiveX control..., that is all you need to do. If you have any question about this project or you do not understand some line of codes, please post your comment and I will try to answer as soon as possible but within my knowledge, because I just have 2 year experience on Visual C. I hope you can understand my example and can apply part of it in your project in the future.

Download demo project - 198 KB



Comments

  • There are no comments yet. Be the first to comment!

Leave a Comment
  • Your email address will not be published. All fields are required.

Top White Papers and Webcasts

  • The impact of a data loss event can be significant. Real-time data is essential to remaining competitive. Many companies can no longer afford to rely on a truck arriving each day to take backup tapes offsite. For most companies, a cloud backup and recovery solution will eliminate, or significantly reduce, IT resources related to the mundane task of backup and allow your resources to be redeployed to more strategic projects. The cloud - can now be comfortable for you – with 100% recovery from anywhere all …

  • Live Event Date: April 22, 2014 @ 1:00 p.m. ET / 10:00 a.m. PT Database professionals — whether developers or DBAs — can often save valuable time by learning to get the most from their new or existing productivity tools. Whether you're responsible for managing database projects, performing database health checks and reporting, analyzing code, or measuring software engineering metrics, it's likely you're not taking advantage of some of the lesser-known features of Toad from Dell. Attend this live …

Most Popular Programming Stories

More for Developers

Latest Developer Headlines

RSS Feeds