Discussion:
Experts pls !!! problem in Adding items to a subclassed CListCtrl class
(too old to reply)
n***@yahoo.com
2006-05-11 15:17:15 UTC
Permalink
Hi,

I am adding item to a subclassed class of CListCtrl. What is teh
correct place to add items in subclassed CListCtrl Class .

I did the folowing steps.Pls let me know where I am goin wrong.

1.In a MFC Doc view with Form view,dragged the CList Control in the
view.

2.Created a class from the class wizard MyListtrlwith base class
CListCtrl.

3.Add a message handler for OnLButtonDown for MyListtrl and added a
Message Box

4.Then in resource view selected teh clistcrl and add memebr variable
and this time selected MyListtrl and named it m_myListCtrl;

5.When I executed the app,I get message caught in the derived
class.Thats fine.
Now I need to add items in this control,Where should I add???
CMyListCtrl::CMyListCtrl()
{
//Set the column name
InsertColumn(1,"H2",LVCFMT_LEFT,100);



//Add items here

}
I addded in MyListtrl CONSTRUCTOR BUT got an debug assertion failed
WITH AFXCM.INL line 186.
Where shoudl I add the items so that it can be seen .I also tried in
adding Create handler of MyListtrl .
When I click right button then my derived class message is getting
called .

Pls guide.
Thanks in advance
AliR
2006-05-11 15:36:44 UTC
Permalink
You want to add your items in the CFormView::OnInitialUpdate, or at least
after the OnInitialUpdate has been called.

AliR.
Post by n***@yahoo.com
Hi,
I am adding item to a subclassed class of CListCtrl. What is teh
correct place to add items in subclassed CListCtrl Class .
I did the folowing steps.Pls let me know where I am goin wrong.
1.In a MFC Doc view with Form view,dragged the CList Control in the
view.
2.Created a class from the class wizard MyListtrlwith base class
CListCtrl.
3.Add a message handler for OnLButtonDown for MyListtrl and added a
Message Box
4.Then in resource view selected teh clistcrl and add memebr variable
and this time selected MyListtrl and named it m_myListCtrl;
5.When I executed the app,I get message caught in the derived
class.Thats fine.
Now I need to add items in this control,Where should I add???
CMyListCtrl::CMyListCtrl()
{
//Set the column name
InsertColumn(1,"H2",LVCFMT_LEFT,100);
//Add items here
}
I addded in MyListtrl CONSTRUCTOR BUT got an debug assertion failed
WITH AFXCM.INL line 186.
Where shoudl I add the items so that it can be seen .I also tried in
adding Create handler of MyListtrl .
When I click right button then my derived class message is getting
called .
Pls guide.
Thanks in advance
n***@yahoo.com
2006-05-11 16:14:43 UTC
Permalink
Thanks for quick response and it worked.
Now When I am adding columsns it worked .
But When I add items I get a debug assertion? Why ??
Pls guide
here is teh code in oninitial update of CFormView

void CMichaelChaseView::OnInitialUpdate()
{

CFormView::OnInitialUpdate();
GetParentFrame()->RecalcLayout();
CString buffer = "Item1";
// ResizeParentToFit();
m_myListCtrl.InsertColumn(0, "Column 1");
m_myListCtrl.InsertColumn(1, "Column 2");
m_myListCtrl.InsertColumn(2, "Column 3");

m_myListCtrl.SetColumnWidth(0, 100);
m_myListCtrl.SetColumnWidth(1, 100);
m_myListCtrl.SetColumnWidth(2, 100);

for(int i=0;i<3;i++)
{
m_myListCtrl.InsertItem(i,(LPCTSTR)buffer);
m_myListCtrl.SetItemText(i,1,(LPCTSTR)buffer);

}
AliR
2006-05-11 17:47:20 UTC
Permalink
I am not sure, things look fine here.

When you get the assert, press retry. Write down the filename and line
number. (Post it here)
Also follow the call stack back to your own code, and make sure that it is
really from InsertItem.


AliR.
Post by n***@yahoo.com
Thanks for quick response and it worked.
Now When I am adding columsns it worked .
But When I add items I get a debug assertion? Why ??
Pls guide
here is teh code in oninitial update of CFormView
void CMichaelChaseView::OnInitialUpdate()
{
CFormView::OnInitialUpdate();
GetParentFrame()->RecalcLayout();
CString buffer = "Item1";
// ResizeParentToFit();
m_myListCtrl.InsertColumn(0, "Column 1");
m_myListCtrl.InsertColumn(1, "Column 2");
m_myListCtrl.InsertColumn(2, "Column 3");
m_myListCtrl.SetColumnWidth(0, 100);
m_myListCtrl.SetColumnWidth(1, 100);
m_myListCtrl.SetColumnWidth(2, 100);
for(int i=0;i<3;i++)
{
m_myListCtrl.InsertItem(i,(LPCTSTR)buffer);
m_myListCtrl.SetItemText(i,1,(LPCTSTR)buffer);
}
n***@yahoo.com
2006-05-11 17:56:27 UTC
Permalink
hI AliR
I am working on Windows XP?does the code SetItemText run fine on XP?
n***@yahoo.com
2006-05-11 17:57:59 UTC
Permalink
tHE assertion is in
WINCTRL2.CPP Line 494
AliR
2006-05-11 18:01:50 UTC
Permalink
Make sure the ListCtrl does not have the LVS_OWNERDATA flag set. (in
resource edit set it to FALSE)

AliR.
Post by n***@yahoo.com
tHE assertion is in
WINCTRL2.CPP Line 494
n***@yahoo.com
2006-05-11 19:10:50 UTC
Permalink
thanks Alir,
It worked
Thanks
Tom

Loading...