Basic VC++ Question
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 8 of 8

Thread: Basic VC++ Question

  1. #1
    Join Date
    Aug 2011
    Posts
    3

    Basic VC++ Question

    Hey all,

    I'm brand new to this forum and brand new to VC++, so go easy on me!

    Here's what I'm trying to do:

    I want to make an incredibly simply .exe program that will read data from a MS Access database which I've linked to an Excel document. I have 3 dropdown menu's and then a bunch of data-output text fields.

    Basically, my question is this: For the 3 dropdown menus, each menu goes from a broad specific category to more and more specific items. So, once you make a selection in the first one, I need to have specific options for the second dropdown menus generated. Furthermore, once a selection is made in the 2nd dropdown menu, there will have to be options generated in the 3rd dropdown menu pulled from the database.

    Once the final selection is made in the 3rd dropdown menu, I'd want to to read the database for that specific item and regurgitate all the values into text fields I've created which I can link to the database.

    Here's what I've got so far: The first dropdown menu is simple, and I've added the options for that. I've made all the text fields where the data from the database will be regurgitated and can even link it, but can't figure out how to do it to a specific cell, and certainly haven't figured out how to get it to link the info automatically upon selection in the 3rd dropdown menu.

    Anyways, as I said, go easy on me, and any help you can provide would be awesome.

    Thanks,

    Riznarf

  2. #2
    Join Date
    Nov 2000
    Location
    Voronezh, Russia
    Posts
    6,024

    Re: Basic VC++ Question

    I believe, menus is not a right choice for the task of the sort. What looks more natural to me is either wizard-like dialog or two pane explorer like window with a categories tree pane on the left.

    Of course dropdown menus could be built dynamically, but dynamic not of the sort you described. And definitely, fighting with old style Windows elements/controls native behavior never was "incredibly simple"
    Best regards,
    Igor

  3. #3
    Join Date
    Aug 2011
    Posts
    3

    Re: Basic VC++ Question

    Quote Originally Posted by Igor Vartanov View Post
    I believe, menus is not a right choice for the task of the sort. What looks more natural to me is either wizard-like dialog or two pane explorer like window with a categories tree pane on the left.

    Of course dropdown menus could be built dynamically, but dynamic not of the sort you described. And definitely, fighting with old style Windows elements/controls native behavior never was "incredibly simple"
    Thanks for the prompt response. Yes, you're right. I have now made a tree pane on the left side of the window, however when I select the final item in the tree, how do I link it to the database to spit out all the data that I need?

  4. #4
    VictorN's Avatar
    VictorN is offline Super Moderator Power Poster
    Join Date
    Jan 2003
    Location
    Wallisellen (ZH), Switzerland
    Posts
    17,472

    Re: Basic VC++ Question

    You could use MFC ODBC classes CDatabase and CRecordset.
    Or ADO
    Or OLEDB
    Or just the old (and deprecated DAO)
    Victor Nijegorodov

  5. #5
    Join Date
    Aug 2011
    Posts
    3

    Re: Basic VC++ Question

    Quote Originally Posted by VictorN View Post
    You could use MFC ODBC classes CDatabase and CRecordset.
    Or ADO
    Or OLEDB
    Or just the old (and deprecated DAO)
    Hahah wow! I'm sure thats good advice, but as I said, brand new VC++ user here, gotta take it easy on me! Whats all that mean?

  6. #6
    VictorN's Avatar
    VictorN is offline Super Moderator Power Poster
    Join Date
    Jan 2003
    Location
    Wallisellen (ZH), Switzerland
    Posts
    17,472

  7. #7
    GCDEF is offline Elite Member Power Poster
    Join Date
    Nov 2003
    Posts
    12,127

    Re: Basic VC++ Question

    Quote Originally Posted by Riznarf View Post
    Hahah wow! I'm sure thats good advice, but as I said, brand new VC++ user here, gotta take it easy on me! Whats all that mean?
    I would just start with the CRecordset class.

  8. #8
    Arjay's Avatar
    Arjay is offline Moderator / MS MVP Power Poster
    Join Date
    Aug 2004
    Posts
    11,370

    Re: Basic VC++ Question

    I would start with the ATL OLEDB consumer classes.

    See my reply and sample code of an app reading an Access db using ATL.

    http://www.codeguru.com/forum/showthread.php?t=337819

    P.S. Before you build the app, change the hardcoded path to the mdb database in the employees.h file. For some dumb reason I hardcoded it in the sample code.

    Using the ATL OLEDB classes, here's how easy it is to read from a db table.

    Code:
    CEmployees employees;
    
    if(SUCCEEDED( hr = employees.OpenAll() ))
    {
      while( S_OK == employees.MoveNext() )
      {
        lvitem.iItem	= uItem;
        lvitem.iSubItem	= 0;
    		    
        lvitem.pszText	= employees.m_FirstName;
        lvitem.cchTextMax	= MAX_LVITEMLEN;
    
        // Insert the item
        m_ctlAccessDataList.InsertItem(&lvitem);
    
        // Set the text for each column (all virtual callbacks)
        m_ctlAccessDataList.SetItemText(uItem, 1, employees.m_LastName);
        m_ctlAccessDataList.SetItemText(uItem, 2, employees.m_HomePhone);
            
        uItem++;
      }
         
    }
    else
    {
      // report error
    }
    Last edited by Arjay; August 31st, 2011 at 03:45 PM.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  


Windows Mobile Development Center


Click Here to Expand Forum to Full Width

This is a CodeGuru survey question.


Featured


HTML5 Development Center