probelm with CListCtrl::SetItemText 
Author Message
 probelm with CListCtrl::SetItemText

hi,
 I have a List defined as a member variable in a dialog and this list is of
type GridListCtrl derived from CListCtrl. If I click one of its subitem a
dialog window  will be poped up to edit the subitem. I realised it with the
following function
void CTabDlg::OnBeginlabeleditAdrTab(NMHDR* pNMHDR, LRESULT* pResult)
{
   .................

    m_editdlg = new CEditAdrTabDlg(item,subitem);
    m_editdlg->Create(IDD_EDITADRTAB,this);
    m_editdlg->ShowWindow(SW_SHOW);

...................

Quote:
}

And in the class CEditAdrTabDlg I defined OnInsert() to insert the data to
the subitem
{
      UpdateData(TRUE);
     CTabDlg *ptabdlg = (CTabDlg*)GetParent();
     ptabdlg->InsertToAdrTab(m_iItem,m_iSubItem,m_MainGrp,m_SubGrp);
    CDialog::CloseWindow();
 }

 The InsertToAdrTab() is defined in CTabDlg as follows:
void CTabDlg::InsertToAdrTab(int item,int subitem, CString s_HighAdr,CString
s_LowAdr)
{
       CString GrpAdr = ConvertToGrpAdr(s_HighAdr,s_LowAdr);
       LPCTSTR p = GrpAdr;
        m_AdrTabList.SetItemText(item,subitem,p);

Quote:
}

The problem is taken place in  m_AdrTabList.SetItemText(item,subitem,p),
then I debug the programm and  step into
the function SetItemText
BOOL CListCtrl::SetItemText(int nItem, int nSubItem, LPCTSTR lpszText)
{
     ASSERT(::IsWindow(m_hWnd));
 =>ASSERT((GetStyle() & LVS_OWNERDATA)==0);  // cant be passed
     ..................

Quote:
}

I used the same function to insert text into the list in this class and
there is no problem, the list is without LVS_OWNERDATA attributes, so whats
wrong with it?  Thanks  in advance.

xingfu



Tue, 07 Jun 2005 12:23:18 GMT  
 probelm with CListCtrl::SetItemText
sorry, it seems that my post is somehow confused with the expression. My
meaning is that I want to execute operations to the parent dialog from child
pop-up dialog, but it seems its not the right way to do it. I create the
pop-up dialog in the CTabDlg and appoint  CTabDlg as parent window. And in
the debug the running is stopped either in ::IsWindow(m_hWnd) or in
ASSERT((GetStyle() & LVS_OWNERDATA)==0) inside of  SetItemText(),  dependent
of the operation I did  in Popup dialog. I am new in MFC and dont know
whats the problem, could you tell me what you did in the same cases?
thanks.


Tue, 07 Jun 2005 18:07:28 GMT  
 probelm with CListCtrl::SetItemText
Hi,

This problem will happen if you have the style set to LVS_OWNERDATA
and are not using a Virtual List.
Set it to LVS_OWNERDRAWFIXED and it should work.

Maybe you are trying to convert the RowList project
to a Virtual List?

A Virtual List is a List Control with a large number of items.

Check the MFC Samples for ROWLIST project for using a List Control.
Look at the sample DBVLIST in MFC Samples for an
example how to create a Virtual list with the LVS_OWNERDRAW style.

Leave the styles for Non-Virtual List Control.
 // default is report view and full row selection
 cs.style &= ~LVS_TYPEMASK;
 cs.style |= LVS_REPORT | LVS_OWNERDRAWFIXED;
 m_bFullRowSel = TRUE;

HTH,

Quote:
> sorry, it seems that my post is somehow confused with the expression. My
> meaning is that I want to execute operations to the parent dialog from
child
> pop-up dialog, but it seems its not the right way to do it. I create the
> pop-up dialog in the CTabDlg and appoint  CTabDlg as parent window. And in
> the debug the running is stopped either in ::IsWindow(m_hWnd) or in
> ASSERT((GetStyle() & LVS_OWNERDATA)==0) inside of  SetItemText(),
dependent
> of the operation I did  in Popup dialog. I am new in mfc and dont know
> whats the problem, could you tell me what you did in the same cases?
> thanks.



Thu, 09 Jun 2005 19:33:55 GMT  
 probelm with CListCtrl::SetItemText
Sorry. I kind of answered too quickly.

Quote:
> > ASSERT((GetStyle() & LVS_OWNERDATA)==0) inside of  SetItemText(),

I always get that error when the style is set. It should not assert if the
style is not set.
I think I had problems when I set the styles in the constructor instead of
OnInitialUpdate()
But if you can already insert items, then that is not the problem.

This might be causing the trouble.

Quote:
>>CTabDlg *ptabdlg = (CTabDlg*)GetParent();

GetParent() doesn't always get what you expect.

I am still shady about GetParentOwner(), GetOwner(), GetSafeOwner(), etc.

What you could do instead is pass a pointer to the dialog before you launch
it.

#include "CGridListCtrl.h"
class CTabDialog : public CDialog
{
    public:
        SetPointer(CGridListCtrl* ptr){ m_pListCtrl = ptr; };
    private:
        CGridListCtrl* m_pListCtrl;

Quote:
}

CTabDialog  Dialog;
Dialog.SetPointer(this);
Dialog.DoModal();

Now, you can acess the class with m_pListCtrl->

You'll get a run around condition when the 2 header files include each
other.
so, put a forward reference before the class.
class CTabDialog;
class CGridListCtrl : public CListCtrl
{
        .....................

Quote:
}

It works kind of like a Modeless Dialog.
It looks to me as you are using a Modeless dialog anyway.
Quote:
>>  m_editdlg = new CEditAdrTabDlg(item,subitem);
>>  m_editdlg->Create(IDD_EDITADRTAB,this);
>>  m_editdlg->ShowWindow(SW_SHOW);

So, just pass the pointer of the parent class to the dialog.
You should see an example how to do this with a Modeless dialog.

HTH,


Quote:
> Hi,

> This problem will happen if you have the style set to LVS_OWNERDATA
> and are not using a Virtual List.
> Set it to LVS_OWNERDRAWFIXED and it should work.

> Maybe you are trying to convert the RowList project
> to a Virtual List?

> A Virtual List is a List Control with a large number of items.

> Check the MFC Samples for ROWLIST project for using a List Control.
> Look at the sample DBVLIST in MFC Samples for an
> example how to create a Virtual list with the LVS_OWNERDRAW style.

> Leave the styles for Non-Virtual List Control.
>  // default is report view and full row selection
>  cs.style &= ~LVS_TYPEMASK;
>  cs.style |= LVS_REPORT | LVS_OWNERDRAWFIXED;
>  m_bFullRowSel = TRUE;

> HTH,


> > sorry, it seems that my post is somehow confused with the expression. My
> > meaning is that I want to execute operations to the parent dialog from
> child
> > pop-up dialog, but it seems its not the right way to do it. I create
the
> > pop-up dialog in the CTabDlg and appoint  CTabDlg as parent window. And
in
> > the debug the running is stopped either in ::IsWindow(m_hWnd) or in
> > ASSERT((GetStyle() & LVS_OWNERDATA)==0) inside of  SetItemText(),
> dependent
> > of the operation I did  in Popup dialog. I am new in mfc and dont know
> > whats the problem, could you tell me what you did in the same cases?
> > thanks.



Fri, 10 Jun 2005 00:43:46 GMT  
 
 [ 4 post ] 

 Relevant Pages 

1. CListCtrl difference InsertItem() and SetItemText(0,...)

2. CListCtrl::SetItemText( ) problem

3. When CListCtrl::SetItemText will not set the text

4. CListCtrl and SetItemText

5. CListCtrl difference InsertItem() and SetItemText(0,...)

6. Need help with CListCtrl.SetItemText()

7. CListCtrl.SetItemText()

8. When CListCtrl::SetItemText will not set the text

9. pointer probelm, please help

10. probelm compiling c code

11. Probelm with Event in a Second Thread

12. Re : GetEnvironmentVariable : Precision of probelm

 

 
Powered by phpBB® Forum Software