Click here to Skip to main content
15,902,114 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Having a bit of an issue accessing my data in order to populate my list control. In my view, I can access my data like this:

C++
myDataArray& myData = GetData();

m_wndFirstName.SetWindowText(myData[nPosition].m_sFirstName);


But, when I create a dialog with a list control, I can not access any data the way that I normally would in my main view. I have overridden OnInitDialog to create my column headers and I can write text directly to it, but I need to use my variables like I would in my view class.

How can I link these classes together??
Posted

Your best bet is to NOT tie them together, but have them both pull data from a third class which exists to expose the data to any class that needs it.
 
Share this answer
 
Comments
DrBones69 26-Jul-12 21:34pm    
Not to sound dumb, but if I can't figure out how to get one class to do this, how do I accomplish your suggestion?
Christian Graus 26-Jul-12 21:40pm    
The methods would have to be static, so you don't need to deal with trying to provide access to a class instance. Or they could take an id of the data set to load, and you could pass that id in to the constructor of your new dialog.
DrBones69 26-Jul-12 22:18pm    
Are you talking about a friend class?
Christian Graus 26-Jul-12 22:19pm    
No. It could be, if you want to hide it from anything that you've not given it access to, but that's an extra layer to add.
DrBones69 26-Jul-12 22:43pm    
I'm soooooo confused!!! I think I'll hit the sack and maybe it will come to me in my sleep as usual. I guess I'm not following your exact meaning or maybe I'm letting my years of Cobol have too much influence over OOP. Sometimes I need things spelled out. Thanks
Just extend your dialog's constructor :) :
C++
CYourDialog : public CDialog
{
  const myDataArray* m_pcData;

  enum { id = IDD_YOURDIALOG };

public:
  CYourDialog(CWnd* pcParent, const myDataArray* pcData)
    : CDialog(pcParent, id), m_pcData(pcData) { ASSERT(m_pcData); }

  virtual BOOL OnInitDialog(); // the Data pointer could be used here
};
 
Share this answer
 
Ok, it turns out that I did not need to create anything special, all I had to do was create some variables and another array in my dialog class. Then copy my data from my main array to the new one. I also found that I can copy anything from my view class my accessing my dialog class through my view class like:

C++
VIEW CLASS

dlg.AnyVariableInMyDialogClass = myDataArray[nPos].m_AnyVariable;


OR load an array like this:

C++
dlg.myDataArray.Add(myData[nPos].m_sFirtName);
...
...
...

I did get a little more creative than the examples above, but I think you'll get the point.

Any comments or suggestions are welcome.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900