Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. Problem with List Control Box in a Pop-up dailog box?

Problem with List Control Box in a Pop-up dailog box?

Scheduled Pinned Locked Moved C / C++ / MFC
databasehelpc++debuggingquestion
5 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • A Offline
    A Offline
    Aoife
    wrote on last edited by
    #1

    I am trying to create an MFC application that uses a List Control Box in a pop-up dialog box. When a Button is pressed in a pop-up dialog box a List Control Box is supposed to be populated with information from an Access database. However when the Button is pressed the program just hangs and is unresponsive. But the puzzling thing is that when the exact same code is used on the main dialog (IDD_MAIN_DIALOG) to an identical List Control Box and Button it works perfectly, with no hanging. I have included the code for the Pop-up dialog box. Any help is greatly appreciated Aoife ***************************************************** #include "stdafx.h" #include "Main.h" #include "DialogBoxDlg.h" #include "afxdb.h" #include "odbcinst.h" #ifdef _DEBUG #define new DEBUG_NEW #undef THIS_FILE static char THIS_FILE[] = __FILE__; #endif ///////////////////////////////////////////////////////////////////////////// // CDialogBoxDlg dialog CDialogBoxDlg ::CDialogBoxDlg (CWnd* pParent /*=NULL*/) : CDialog(CDialogBoxDlg ::IDD, pParent) { //{{AFX_DATA_INIT(CDialogBoxDlg ) // NOTE: the ClassWizard will add member initialization here //}}AFX_DATA_INIT } void CDialogBoxDlg ::DoDataExchange(CDataExchange*pDX) { CDialog::DoDataExchange(pDX); //{{AFX_DATA_MAP(CDialogBoxDlg ) // NOTE: the ClassWizard will add DDX and DDV calls here DDX_Control(pDX, IDC_SMS_MYLISTCONTROL,m_SMSMyListControl); //}}AFX_DATA_MAP } BEGIN_MESSAGE_MAP(CDialogBoxDlg , CDialog) //{{AFX_MSG_MAP(CDialogBoxDlg ) ON_BN_CLICKED(IDC_BUTTON, OnButtonPressed) //}}AFX_MSG_MAP END_MESSAGE_MAP() ///////////////////////////////////////////////////////////////////////////// // CDialogBoxDlg message handlers void CDialogBoxDlg ::OnButtonPressed() { CDatabase database; CString SqlString; CString sNumber, sSender, sDate, sMessage; CString sDriver = "MICROSOFT ACCESS DRIVER (*.mdb)"; CString sDsn; CString sFile = "c:\\THEPROJECT\\Interface\\Project_Databases.mdb"; int iRec =0; //Build ODBC connection string sDsn.Format("ODBC;DRIVER={%s};DSN='';DBQ=%s",sDriver,sFile); TRY { //Open the Database database.Open(NULL,false,false,sDsn); //Allocte the Record set CRecordset recset (&database); //Build the SQL statement SqlString = "SELECT Number, Sender, Date, Message " "FROM pc_Inbox"; //Execute the query recset.Open(CRecordset::forwardOnly,SqlString,CRecordset::readOnly); //Populate the Grids ListView_SetExtendedListViewStyle(m_SMSMyListControl,LVS_EX_GRIDLINES); //Column width and

    R 1 Reply Last reply
    0
    • A Aoife

      I am trying to create an MFC application that uses a List Control Box in a pop-up dialog box. When a Button is pressed in a pop-up dialog box a List Control Box is supposed to be populated with information from an Access database. However when the Button is pressed the program just hangs and is unresponsive. But the puzzling thing is that when the exact same code is used on the main dialog (IDD_MAIN_DIALOG) to an identical List Control Box and Button it works perfectly, with no hanging. I have included the code for the Pop-up dialog box. Any help is greatly appreciated Aoife ***************************************************** #include "stdafx.h" #include "Main.h" #include "DialogBoxDlg.h" #include "afxdb.h" #include "odbcinst.h" #ifdef _DEBUG #define new DEBUG_NEW #undef THIS_FILE static char THIS_FILE[] = __FILE__; #endif ///////////////////////////////////////////////////////////////////////////// // CDialogBoxDlg dialog CDialogBoxDlg ::CDialogBoxDlg (CWnd* pParent /*=NULL*/) : CDialog(CDialogBoxDlg ::IDD, pParent) { //{{AFX_DATA_INIT(CDialogBoxDlg ) // NOTE: the ClassWizard will add member initialization here //}}AFX_DATA_INIT } void CDialogBoxDlg ::DoDataExchange(CDataExchange*pDX) { CDialog::DoDataExchange(pDX); //{{AFX_DATA_MAP(CDialogBoxDlg ) // NOTE: the ClassWizard will add DDX and DDV calls here DDX_Control(pDX, IDC_SMS_MYLISTCONTROL,m_SMSMyListControl); //}}AFX_DATA_MAP } BEGIN_MESSAGE_MAP(CDialogBoxDlg , CDialog) //{{AFX_MSG_MAP(CDialogBoxDlg ) ON_BN_CLICKED(IDC_BUTTON, OnButtonPressed) //}}AFX_MSG_MAP END_MESSAGE_MAP() ///////////////////////////////////////////////////////////////////////////// // CDialogBoxDlg message handlers void CDialogBoxDlg ::OnButtonPressed() { CDatabase database; CString SqlString; CString sNumber, sSender, sDate, sMessage; CString sDriver = "MICROSOFT ACCESS DRIVER (*.mdb)"; CString sDsn; CString sFile = "c:\\THEPROJECT\\Interface\\Project_Databases.mdb"; int iRec =0; //Build ODBC connection string sDsn.Format("ODBC;DRIVER={%s};DSN='';DBQ=%s",sDriver,sFile); TRY { //Open the Database database.Open(NULL,false,false,sDsn); //Allocte the Record set CRecordset recset (&database); //Build the SQL statement SqlString = "SELECT Number, Sender, Date, Message " "FROM pc_Inbox"; //Execute the query recset.Open(CRecordset::forwardOnly,SqlString,CRecordset::readOnly); //Populate the Grids ListView_SetExtendedListViewStyle(m_SMSMyListControl,LVS_EX_GRIDLINES); //Column width and

      R Offline
      R Offline
      Ravi Bhavnani
      wrote on last edited by
      #2

      Um... have you tried stepping into OnButtonPressed()? Where does it hang? /ravi "There is always one more bug..." http://www.ravib.com ravib@ravib.com

      A 2 Replies Last reply
      0
      • R Ravi Bhavnani

        Um... have you tried stepping into OnButtonPressed()? Where does it hang? /ravi "There is always one more bug..." http://www.ravib.com ravib@ravib.com

        A Offline
        A Offline
        Aoife
        wrote on last edited by
        #3

        Please be patient with me, I'm a student! ;-) I have tried stepping into it, but... I decided to step through the Button and List Control box (In the Main Dialog)that works properly so that I could see how that one worked. But while stepping through it pop-up boxes appear requesting that I find the source for certain .C files. I searched my computer for them but couldn't find them. I do have MSDN VC++ libraries installed. If I cancel out of these boxes the debugger starts going through Assembly code. Why does this happen while debugging, when that part of the application works properly when the application is executed? So I can't debug the OnButtonPressed() because the same Find Source pop-up boxes appear.

        1 Reply Last reply
        0
        • R Ravi Bhavnani

          Um... have you tried stepping into OnButtonPressed()? Where does it hang? /ravi "There is always one more bug..." http://www.ravib.com ravib@ravib.com

          A Offline
          A Offline
          Aoife
          wrote on last edited by
          #4

          After a quick lesson in debugging.. I have found that it is hanging on this line, //Populate the Grids ListView_SetExtendedListViewStyle(m_SMSMyListControl,LVS_EX_GRIDLINES);

          R 1 Reply Last reply
          0
          • A Aoife

            After a quick lesson in debugging.. I have found that it is hanging on this line, //Populate the Grids ListView_SetExtendedListViewStyle(m_SMSMyListControl,LVS_EX_GRIDLINES);

            R Offline
            R Offline
            Ravi Bhavnani
            wrote on last edited by
            #5

            Perhaps it's dying because you haven't yet inserted the columns? Try setting the LVS_EX_GRIDLINES style after you define the control's columns. Hope this helps! /ravi "There is always one more bug..." http://www.ravib.com ravib@ravib.com

            1 Reply Last reply
            0
            Reply
            • Reply as topic
            Log in to reply
            • Oldest to Newest
            • Newest to Oldest
            • Most Votes


            • Login

            • Don't have an account? Register

            • Login or register to search.
            • First post
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • World
            • Users
            • Groups