Advertisement

08.14.2008 at 12:39AM PDT, ID: 23647298
[x]
Attachment Details
[x]
The Solution Rating System

With so many solutions, how can you tell which solutions are most likely to help you and which ones are not? To provide you with a tool to use, we rate our solutions based on various elements that most accurately determine if a solution is a quality solution. To explain what factors affect the solution rating, here are the elements we take into consideration when formulating our solution rating.

  • The Grade of the Solution
  • The Zone Rank of the Expert Providing the Solution
  • The Number of Author and Expert Comments
  • The Number of Experts Contributing
  • The Feedback of the Community

Your Input Matters
Because of the way the system is set up, the most important variable in this equation is you. As a member of Experts Exchange, you are able to cast your vote on the quality of the solutions in regard to how complete, accurate, helpful and easy to understand each solution is. When you provide your feedback, each rating is adjusted accordingly. So, if you see a solution that has a poor rating that you think is a good solution, let us know by rating it. As you do, the rating will be adjusted and will become more accurate for other members of our site.

If you have any suggestions that you would like to make for our rating system, please ask a question in the Suggestions Zone of Community Support.

Thank you!

7.6

Use CListCtrl in Dialog

Asked by dev_yinz in Windows MFC Programming, Microsoft Visual C++

Tags:

I am going to use CListCtrl in a MFC Modal Dialog to list the invoice items to the user. I initiate the column of CListCtrl in the OnInitDialog stage and successful. And I try to update the content of CListCtrl in the DoDataExchange stage but failed. I debug the code and found it may because of NULL m_hWnd of CListCtrl. The code is as below. Any one knows what is right way to add the items to the CListCtrl so the user can see the content in the CListCtrl when user opens the Dialog?

Code:
// I initiate the column of CListCtrl in the OnInitDialog stage, and successful
BOOL CReceiptDlg::OnInitDialog()
{
CDialog::OnInitDialog();
m_ReceiptStatListCtrl.InsertColumn(0, "ID", LVCFMT_CENTER, 50, 0);
m_ReceiptStatListCtrl.InsertColumn(1, "Entry Type", LVCFMT_CENTER, 80, 1);
m_ReceiptStatListCtrl.InsertColumn(2, "Date Time", LVCFMT_CENTER, 120, 2);
m_ReceiptStatListCtrl.InsertColumn(3, "Description", LVCFMT_CENTER, 150, 3);
m_ReceiptStatListCtrl.InsertColumn(4, "Amount", LVCFMT_CENTER, 100, 4);

return TRUE;
}

void CReceiptDlg::DoDataExchange(CDataExchange* pDX)
{
if (!pDX->m_bSaveAndValidate)
{
// if the exchange data is to update the control, I will populate the data to contrl before update
UpdateReceiptStat();
}
CDialog::DoDataExchange(pDX);
// Update the other controls successfully
DDX_Text(pDX, IDC_RECEIPT_ID, m_ReceiptId);
DDX_Text(pDX, IDC_RECEIPT_DATE_TIME, m_StrCreationDateTime);
DDX_Text(pDX, IDC_RECEIPT_CHARGE, m_StrReceiptCharge);
DDX_Text(pDX, IDC_RECEIPT_PAYMENT, m_StrReceiptPayment);
DDX_Text(pDX, IDC_RECEIPT_ADJ, m_StrReceiptAdj);
DDX_Text(pDX, IDC_RECEIPT_TOTAL, m_StrReceiptTotal);

// Update the CListCtrl
DDX_Control(pDX, IDC_RECEIPT_STAT_LIST, m_ReceiptStatListCtrl);
}

// The function to update the receipt statement data
void CReceiptDlg::UpdateReceiptStat()
{
// Clear the memory of the old receipt statements
if (m_pReceipt->nNumOfReceiptStat > 0)
{
  delete[] m_pReceiptStat;
  m_pReceiptStat = NULL;
}

// Read the receipt statements from Database
m_pReceiptStat = theApp.adoAccess.GetReceiptStat(m_pReceipt, NULL, time(NULL),100);

// Delete the content in the CListCtrl if has
if (m_ReceiptStatListCtrl.m_hWnd != NULL)
{
m_ReceiptStatListCtrl.DeleteAllItems();
}

// Insert items to the CListCtrl control
CString StrDateTime;
CString StrDoubleValue;
tm *tmDateTime = NULL;
RECEIPT_STAT *pFirstReceiptStat = m_pReceiptStat;

// Loop to insert the items to the CListCtrl
for (int i=0; i<m_pReceipt->nNumOfReceiptStat; pFirstReceiptStat++)
{
StrDoubleValue.Format("%d", i);
m_ReceiptStatListCtrl.InsertItem(i, CSPTR(StrDoubleValue));  // Error here

// Entry Type Column
switch((ENTRY_TYPE)m_pReceiptStat->nEntryType)
{
case Charge:
m_ReceiptStatListCtrl.SetItemText(i, 1, CString("Charge")); // Error here
break;
case Payment:
m_ReceiptStatListCtrl.SetItemText(i, 1, CString("Payment")); // Error here
break;
case Adjustement:
m_ReceiptStatListCtrl.SetItemText(i, 1, CString("Adjustment")); // Error here
break;
case Refund:
m_ReceiptStatListCtrl.SetItemText(i, 1, CString("Refund")); // Error here
break;
default:
m_ReceiptStatListCtrl.SetItemText(i, 1, CString("")); // Error here
break;
}
// DateTime Column
tmDateTime = localtime(&m_pReceiptStat->lStartDateTime);
StrDateTime.Format(" %.2d/%.2d/%.4d %.2d:%.2d:%.2d", tmDateTime->tm_mday,
tmDateTime->tm_mon, tmDateTime->tm_year + 1900,
tmDateTime->tm_hour, tmDateTime->tm_min, tmDateTime->tm_sec);
m_ReceiptStatListCtrl.SetItemText(i, 2, StrDateTime); // Error here

// Description, Amount
m_ReceiptStatListCtrl.SetItemText(i, 3, m_pReceiptStat->nDescription); // Error here
StrDoubleValue.Format("%.2f", m_pReceiptStat->dAmount);
m_ReceiptStatListCtrl.SetItemText(i, 4, StrDoubleValue); // Error here

i++;
} // end of loop
}Start Free Trial
[+][-]08.14.2008 at 01:00AM PDT, ID: 22228375

View this solution now by starting your 7-day free trial. Setting up your free trial is quick, easy, and secure. We will return you to this solution, unlocked, when you're done.

 

About this solution

Zones: Windows MFC Programming, Microsoft Visual C++
Tags: Visual C++ (Visual Studio 2005)
Sign Up Now!
Solution Provided By: AndyAinscow
Participating Experts: 1
Solution Grade: B
 
 
[+][-]08.14.2008 at 01:55AM PDT, ID: 22228613

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
 
Loading Advertisement...
20081112-EE-VQP-42 / EE_QW_2_20070628