Click here to Skip to main content
15,921,179 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
GeneralRe: basic window question Pin
Nish Nishant16-Apr-02 12:30
sitebuilderNish Nishant16-Apr-02 12:30 
GeneralRe: basic window question Pin
Mazdak16-Apr-02 10:08
Mazdak16-Apr-02 10:08 
GeneralRe: basic window question Pin
lucy16-Apr-02 15:22
lucy16-Apr-02 15:22 
Generalradio buttons, edit boxes, etc Pin
Rajveer16-Apr-02 8:46
Rajveer16-Apr-02 8:46 
GeneralRe: radio buttons, edit boxes, etc Pin
lucy16-Apr-02 8:54
lucy16-Apr-02 8:54 
Generalincluding .lib and .dll files Pin
megadith16-Apr-02 8:37
megadith16-Apr-02 8:37 
GeneralRe: including .lib and .dll files Pin
Mazdak16-Apr-02 8:41
Mazdak16-Apr-02 8:41 
QuestionProblem with List Control Box in a Pop-up dailog box? Pin
Aoife16-Apr-02 7:05
Aoife16-Apr-02 7:05 
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 heading
m_SMSMyListControl.InsertColumn(0, "SMS No.",LVCFMT_LEFT, -1,0);
m_SMSMyListControl.InsertColumn(1, "Sender",LVCFMT_LEFT, -1,1);
m_SMSMyListControl.InsertColumn(2, "Date",LVCFMT_LEFT, -1,2);
m_SMSMyListControl.InsertColumn(3, "Message",LVCFMT_LEFT, -1,3);

m_SMSMyListControl.SetColumnWidth(0, 100);
m_SMSMyListControl.SetColumnWidth(1, 100);
m_SMSMyListControl.SetColumnWidth(2, 100);
m_SMSMyListControl.SetColumnWidth(3, 200);

//Loop through each record
while (!recset.IsEOF())
{
//Copy each column into a variable
recset.GetFieldValue("Number",sNumber);
recset.GetFieldValue("Sender",sSender);
recset.GetFieldValue("Date",sDate);
recset.GetFieldValue("Message",sMessage);

//Insert values into the list control
iRec = m_SMSMyListControl.InsertItem(0,sNumber,0);
m_SMSMyListControl.SetItemText(0,1,sSender);
m_SMSMyListControl.SetItemText(0,2,sDate);
m_SMSMyListControl.SetItemText(0,3,sMessage);

//Go to the next record
recset.MoveNext();
}

//Close the Database
database.Close();
}

CATCH(CDBException, e)
{
//If a database exception occured, show an error message
AfxMessageBox("Database error: "+e->m_strError);
}
END_CATCH;

}

AnswerRe: Problem with List Control Box in a Pop-up dailog box? Pin
Ravi Bhavnani16-Apr-02 7:35
professionalRavi Bhavnani16-Apr-02 7:35 
GeneralRe: Problem with List Control Box in a Pop-up dailog box? Pin
Aoife16-Apr-02 8:14
Aoife16-Apr-02 8:14 
GeneralRe: Problem with List Control Box in a Pop-up dailog box? Pin
Aoife16-Apr-02 9:31
Aoife16-Apr-02 9:31 
GeneralRe: Problem with List Control Box in a Pop-up dailog box? Pin
Ravi Bhavnani16-Apr-02 10:14
professionalRavi Bhavnani16-Apr-02 10:14 
Generalconverting _variant_t to string Pin
16-Apr-02 7:00
suss16-Apr-02 7:00 
GeneralRe: converting _variant_t to string Pin
NapiSpooler16-Apr-02 8:35
NapiSpooler16-Apr-02 8:35 
GeneralRe: converting _variant_t to string Pin
Tim Smith16-Apr-02 10:13
Tim Smith16-Apr-02 10:13 
GeneralMigration java -> c++ Pin
Zizilamoroso16-Apr-02 6:08
Zizilamoroso16-Apr-02 6:08 
GeneralRe: Migration java -> c++ Pin
dazinith16-Apr-02 6:16
dazinith16-Apr-02 6:16 
GeneralRe: Migration java -> c++ Pin
Zizilamoroso16-Apr-02 7:00
Zizilamoroso16-Apr-02 7:00 
GeneralRe: Migration java -> c++ Pin
Ravi Bhavnani16-Apr-02 6:28
professionalRavi Bhavnani16-Apr-02 6:28 
GeneralISAPI filter for raw data Pin
rajacm16-Apr-02 5:41
rajacm16-Apr-02 5:41 
GeneralOFNHookProc Pin
Anthony988716-Apr-02 5:35
Anthony988716-Apr-02 5:35 
GeneralBest collection class for CPoint object. Pin
kursatkaraca16-Apr-02 5:28
kursatkaraca16-Apr-02 5:28 
GeneralUNICODE Pin
Rage16-Apr-02 5:23
professionalRage16-Apr-02 5:23 
GeneralRe: UNICODE Pin
Philip Patrick16-Apr-02 6:35
professionalPhilip Patrick16-Apr-02 6:35 
GeneralRe: UNICODE Pin
Le centriste16-Apr-02 6:52
Le centriste16-Apr-02 6:52 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.