StanChart
asked on
CPropertySheet - Update CListCtrl on inactive page
Hi,
I have an application which has three tabs. Each tab has a CListCtrl and when the application is started, I want to insert some items into those listboxes. The problem I am having is that I get debug assertion errors because if I try to insert an item into a listbox located on a sheet that is not active, the hwnd pointer is NULL.
I can think of two ways of getting around this. One is to set the page as active everytime an item is inserted into the listbox. This is not the way I would like to do this because I do not want the application to switch pages by itself all the time. The second way would be to check of the page is active and if not, store the item to insert into a list. When the page gets activated, the list would be emptied into the list box.
I was wondering if there is any other way I can do this.
Your help is greatly appreciated.
Cheers
I have an application which has three tabs. Each tab has a CListCtrl and when the application is started, I want to insert some items into those listboxes. The problem I am having is that I get debug assertion errors because if I try to insert an item into a listbox located on a sheet that is not active, the hwnd pointer is NULL.
I can think of two ways of getting around this. One is to set the page as active everytime an item is inserted into the listbox. This is not the way I would like to do this because I do not want the application to switch pages by itself all the time. The second way would be to check of the page is active and if not, store the item to insert into a list. When the page gets activated, the list would be emptied into the list box.
I was wondering if there is any other way I can do this.
Your help is greatly appreciated.
Cheers
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Hi,
Thanks for your reply.
Here is what I am currently doing. I derived my class from CPropertySheet and use AddPage(&myPages) to add three pages to the property sheet. Page 1 and Page 2 have the list controls I want to update. If I add items to the list boxes in the OnInit override, I do not get the null hwnd.
The application I am writing is a server. Everytime I receive a request, I want to update the list controls (might be on either page 1 or page 2 depending on the request received by the server). The problem I have now is that I have my request handler in a separate class (created and stored inside the dialog) which has a pointer to the property sheet. The property sheet has methods to return a pointer to each page. Therefore when I want to update a list control after I process the request, I do something like this inside my request handler:
m_pDialog->GetPage1()->Add RequestLog ("User Logging In");
or
m_pDialog->GetPage2()->Add ServerLog( "Stored user login event");
The methods AddRequestLog and AddServerLog look something like this:
************************** ********** *****
// Add the server log to the list box.
m_ctrlServerLog.InsertItem (0, logDateTime.Format("%d-%b- %y %H:%M:%S"));
m_ctrlServerLog.SetItemDat a(0, 0);
m_ctrlServerLog.SetItemTex t(0, SL_LOG_COLUMN, log);
UpdateData(FALSE);
return TRUE;
************************** ********** *****
The only way this works is if I set the page active before I update the list box. I do this when the GetPage1() or GetPage2() methods are called.
Is there something I am doing wrong here?
Thanks again for your help.
Cheers
Thanks for your reply.
Here is what I am currently doing. I derived my class from CPropertySheet and use AddPage(&myPages) to add three pages to the property sheet. Page 1 and Page 2 have the list controls I want to update. If I add items to the list boxes in the OnInit override, I do not get the null hwnd.
The application I am writing is a server. Everytime I receive a request, I want to update the list controls (might be on either page 1 or page 2 depending on the request received by the server). The problem I have now is that I have my request handler in a separate class (created and stored inside the dialog) which has a pointer to the property sheet. The property sheet has methods to return a pointer to each page. Therefore when I want to update a list control after I process the request, I do something like this inside my request handler:
m_pDialog->GetPage1()->Add
or
m_pDialog->GetPage2()->Add
The methods AddRequestLog and AddServerLog look something like this:
**************************
// Add the server log to the list box.
m_ctrlServerLog.InsertItem
m_ctrlServerLog.SetItemDat
m_ctrlServerLog.SetItemTex
UpdateData(FALSE);
return TRUE;
**************************
The only way this works is if I set the page active before I update the list box. I do this when the GetPage1() or GetPage2() methods are called.
Is there something I am doing wrong here?
Thanks again for your help.
Cheers
ASKER
>What you should do is to initialize your listboxes in the OnInitDialog method of each of your CPropertyPages. This method is called only once when the dialog is about to be shown for the first time.
This is how I initialize the list controls on my property page's OnInit method which works.
m_ctrlServerLog.InsertColu mn(SL_LOGD ATETIME_CO LUMN, _T("Log Date/Time"), LVCFMT_LEFT, 105);
m_ctrlServerLog.InsertColu mn(SL_LOG_ COLUMN, _T("Log Details"), LVCFMT_LEFT, 600);
m_ctrlServerLog.SendMessag e(LVM_SETE XTENDEDLIS TVIEWSTYLE , 0, LVS_EX_FULLROWSELECT|LVS_E X_GRIDLINE S);
Cheers
This is how I initialize the list controls on my property page's OnInit method which works.
m_ctrlServerLog.InsertColu
m_ctrlServerLog.InsertColu
m_ctrlServerLog.SendMessag
Cheers
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Thanks much!
What you should do is to initialize your listboxes in the OnInitDialog method of each of your CPropertyPages. This method is called only once when the dialog is about to be shown for the first time.
> I try to insert an item into a listbox located on a sheet that is not active, the hwnd pointer is NULL.
This is because the property page (not sheet, the sheet is the object that holds the pages/tabs) was not created yet (i.e. OnInitDialog has not been called for that page). After that, your HWND will not be NULL even if the page is inactive.