Link to home
Start Free TrialLog in
Avatar of trimtrom
trimtrom

asked on

Getting the activeview from a dialogbox

Hello,
I am a VC++ beginner using VC++6.0 Prof on Windows 98.

I have an MDI app in which I have so far created one child window.  This is a splitter window, one part of which is a CListView (in reportview with subitems).  I have got so far as doubleclicking on an item from the listview, which produces a Propertysheet with three pages.  This propertysheet is supposed to show data relating to the item in the listview.

I have the following problems:

1)  I need to get a pointer to the view that was active before I called up the Propertypages.

2)  With this I need to get the itemtext of the selected item in the listview.

I do not know how to do either of the above items.  I have produced the following code:

void CAddrPage1::GetRecordset()
{
        //parent of the propertysheet
 CMDIChildWnd* mpaul = (CMDIChildWnd*)GetParent();
        //active view of the parent
 CListView* msteve = (CListView*)mpaul->GetActiveView();
        //underlying listcontrol
 CListCtrl &mjohn = msteve->GetListCtrl();
        //don't know how to get selected item
 CString mhelen = mjohn.GetItemText(2,0);
        //SQL statement
 CString mtext = "Select * from AddressBook where Displayname = '" +
 mhelen + "'";    
        // recordset class ClassWizard created
 m_PSet = new CAddrRset1(mtext);  
        //error handling & open recordset for use in prop pages
 m_PSet->Open();
}

This code produces a runtime error saying it can't find the CListCtrl. The code is supposed to get the listview item, and with it create the recordset needed to prime the propertypages which I am calling up.  I call it in OnCreate() of page one of the new propertypages.

I would be very grateful for code showing how to do the above. Especially I am interested in how to extract the itemtext of the selected listview item.

Thanks,
Paul Trimming
ASKER CERTIFIED SOLUTION
Avatar of MatthiasLange
MatthiasLange

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of naveenkohli
naveenkohli

I think you really don't need to go thru all this pain of getting the active view and stuff. You can accomplish your thing by passing the pointer to the selected item in the constructor of your property sheet. For this you just need to your own property sheet class which has LV_ITEM pointer as constructor argument.

CPropertySheet propSheet (LV_ITEM* pItem);

I think it should work for you.... Try it. I have not tried it..