Thread: ListView 6.0 OnListItemClick Problem

  1. #1
    Registered User
    Join Date
    Oct 2001
    Posts
    13

    Question ListView 6.0 OnListItemClick Problem

    I have added the MS Common Controls ActiveX controls Version 6.0. I am using the MS ListView Control Version 6.0. VC++ 6.0 has added all the neccesary non-editable classes for the control and its objects.

    These controls use ListItem Classes, which are IDispatch-able, for each item in the List.

    I have mapped the control's OnClick event for ListItems.

    Everything seems to go fine, I can get the ListItem in the OnClick call, but for some reason, the event seems to clear the ListItem out of ListView.

    Subsequent clicks to the last clicked items results in nasty pointer errors, "the address at hex value cannot be 'read.'" A Debug reveals that the error is in the MSCOMCTRL32.OCX, of course.

    It seems that the ListItem object is being destructed or something.

    What am I missing? I have this feeling I should be passing the LPDISPATCH onto something, but to what, by what method call?

    I shouldn't have to re-add the ListItem to the ListView, should I?

    This is the code for the OnItemClick:

    Code:
    void CHlfavsDlg::OnItemClickListviewFavs(LPDISPATCH Item) 
    {
            VARIANT tag_data;
    	CListItem l_item(Item); // CListItem construct can take a LPDISPATCH
    	tag_data = l_item.GetTag();
    	if( tag_data.vt = VT_BSTR ) // I am storing a string in the tag data
    	{
    		m_ip = tag_data.bstrVal; // This variable is set properly.
    	}
    }
    There doesn't seem to be anything to horrible there, nothing that would destroy my ListItem.

    Any suggestions?
    Last edited by blundstrom; 07-21-2002 at 01:14 AM.

  2. #2
    Registered User
    Join Date
    Oct 2001
    Posts
    13

    Figured out my mistake!!!

    Nevermind,

    I knew it was a simple solution:

    Code:
    void CHlfavsDlg::OnItemClickListviewFavs(LPDISPATCH Item) 
    {	
    	VARIANT tag_data;
    	CListItem list_item;
    //
    // Instead of using contructor, you use AttachDispatch with
    // the AutoRelease set to FALSE, so when the LPDISPATCH
    // fall out of scope, it doesn't delete the associated ListItem
    //
    
    	list_item.AttachDispatch( Item, FALSE ); // inhertied from IDispatch
    	
    	long index = list_item.GetIndex();
    	tag_data = list_item.GetTag();
    	if( tag_data.vt = VT_BSTR ) // I am storing a string in the tag data
    	{
    		m_ip = tag_data.bstrVal; // This variable is set properly.
    		m_edit_test.SetWindowText( (LPCTSTR)m_ip );
    	}
    	
    }

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Bin packing problem....
    By 81N4RY_DR460N in forum C++ Programming
    Replies: 0
    Last Post: 08-01-2005, 05:20 AM
  2. Words and lines count problem
    By emo in forum C Programming
    Replies: 1
    Last Post: 07-12-2005, 03:36 PM
  3. Problem with Visual C++ 6.0
    By toonlover in forum C++ Programming
    Replies: 4
    Last Post: 05-25-2005, 09:32 PM
  4. Visual Studio 6.0 Help
    By L_I_Programmer in forum C++ Programming
    Replies: 1
    Last Post: 03-24-2003, 10:35 PM
  5. ListView Version 6.0 and ImageLists
    By blundstrom in forum Windows Programming
    Replies: 0
    Last Post: 07-26-2002, 09:35 AM