Click here to Skip to main content
15,902,775 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
C#
hello,

I am trying to pass variable of one class to other class, i did this by calling that doalogbox using DoModal method . But it give retry,Abort,ignore type of messagebox/ Exception.
Is there any way to access variable of one class to other class.
Posted
Comments
Jochen Arndt 17-Jan-16 7:30am    
There are many methods to do that. Examples are passing it using an appropiate constructor (MyClass(varType varName)), providing some kind of Set function (SetVar(varType varName)) or using the Windows message system with a user defined message (SendMessage(), PostMessage()).

But without seeing the code portions actually used, it is impossible to tell you what is going wrong.

So you might add the necessary code snippets by editing your question. To do this use the green 'Improve question' link.
Kishor-KW 17-Jan-16 7:48am    
please reply
Kishor-KW 17-Jan-16 7:35am    
in CMyDialog1 class file:
m_Variable =CompanyName;

and in CMyDialog2 class file:
CString strvalue;
CMyDialog1 dlg;
strvalue= dlg.m_Variable ;

if we do not call DoModal method before assignment then dlg.m_intVariable is empty.
Jochen Arndt 17-Jan-16 7:56am    
The code looks a bit incomplete.
Please explain what do want to do:
- Set a variable of CMyDialog1 before showing the dialog?
- Retrieve the value after the dialog has been closed?
- Or even both?
Kishor-KW 17-Jan-16 8:12am    
In CMyDialog1 class I am assigning a value to the variable m_Variable. after closing CMyDialog1 , CMyDialog2 is opened and now here I assigned m_Variable value
to variable of CMyDialog2

Both CMyDialog1 and CMyDialog2 are individual DialogBoxe with there individual class

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