Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

List Control Box in a ctrlTab?

Status
Not open for further replies.

AoifeC

Programmer
Apr 12, 2002
7
IE
The following code to populate a List Control Box with data from a database when a button is pressed works successfully when the List Control Box is placed on the main IDD_DIALOG. However when the List Control Box and button is placed on a tab, eg IDD_TAB1 the program hangs when the button is pressed.
(The header files "afxdb.h" and "odbcinst.h" are included in both the mainDlg.cpp and Tab1Dlg.cpp)

Any ideas as to why this is happening?
Any help is greatly appreciated.
Aoife

***********************************************************

void CInterfaceDlg::OnMainRead()
{

CDatabase database;
CString SqlString;
CString sNumber, sSender, sDate, sMessage;
CString sDriver = "MICROSOFT ACCESS DRIVER (*.mdb)";
CString sDsn;
CString sFile = "c:\\THE PROJECT\\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_listControl,LVS_EX_GRIDLINES);

//Column width and heading
m_listControl.InsertColumn(0, "SMS No.", LVCFMT_LEFT, -1,0);
m_listControl.InsertColumn(1, "Sender", LVCFMT_LEFT, -1,1);
m_listControl.InsertColumn(2, "Date", LVCFMT_LEFT, -1,2);
m_listControl.InsertColumn(3, "Message", LVCFMT_LEFT, -1,3);

m_listControl.SetColumnWidth(0, 100);
m_listControl.SetColumnWidth(1, 100);
m_listControl.SetColumnWidth(2, 100);
m_listControl.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_listControl.InsertItem(0,sNumber,0);
m_listControl.SetItemText(0,1,sSender);
m_listControl.SetItemText(0,2,sDate);
m_listControl.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;

}
 
Set a breakpoint at "while (!recset.IsEOF())" and step through the code to see where it goes tits up. If you can't fix it from that then come back with the results.

HTH



William
Software Engineer
ICQ No. 56047340
 
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 OnMainRead() because the same Find Source pop-up boxes appear.
 
After a quick lesson in debugging..

I have found that it is hanging on this line,

//Populate the Grids
ListView_SetExtendedListViewStyle(m_listControl,LVS_EX_GRIDLINES);
 
Yes, and I'm not surprised.

Try changing that line to :
m_ListControl.SetExtendedStyle(m_listControl.GetExtendedStyle(), LVS_EX_GRIDLINES) ;

HTH.


William
Software Engineer
ICQ No. 56047340
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top