-
May 3rd, 2010, 10:35 AM
#1
MFC - How to set value of edit box on initialisation of dialog
This feels like it should be the simplest thing in the world, but after days of searching the web, and reading through tens of tutorials/technical papers, I'm still none the wiser about how to do this.
Basically, there is functionality in my application to edit the member data of objects stored in a doubly linked list. The add functionality is absolutely fine as the controls start blank, but for the edit I need to be able to populate the edit controls with the current data from the object.
For example, I have an IDC_EDIT control, described in the DoDataExchange function as:
Code:
DDX_Text(pDX, IDC_EDIT3, manufacturer);
this has the variable manufacturer assigned to it as a CString value. Not all of the edit boxes on the page are this type, but I just include this for example.
I just need someone to point me in the right direction on how to set the values of these edit boxes so that they show up in the edit boxes on the .DoModal() call. I'm at my wit's end with this one!
Thanks in advance.
-
May 3rd, 2010, 10:42 AM
#2
Re: MFC - How to set value of edit box on initialisation of dialog
Assign manufacturer whatever value you want to appear in the edit control. Do it after the dialog object is created, but before CDialog:oModal is called. One typical implementation may look like
Code:
CMyDialog dlg;
dlg.manufacturer = "Acme";
dlg.DoModal();
-
May 4th, 2010, 05:54 AM
#3
Re: MFC - How to set value of edit box on initialisation of dialog
Aah, you sir are a hero! I will try this now, thanks
-
May 4th, 2010, 12:34 PM
#4
Re: MFC - How to set value of edit box on initialisation of dialog
Ooh another problem. What you suggested worked a treat with the edit boxes, is there something special I need to do for 'CComboBox' as CComboBox::SetCurSel is throwing assert errors for me.
In my add dialog, I get the selection made by the user with CComboBox::GetCurSel() which gives me an integer and the whole process is fine, but SetCurSel with the same integer isn't working on initialisation.
Thanks for your help before!
-
May 4th, 2010, 12:49 PM
#5
Re: MFC - How to set value of edit box on initialisation of dialog
Originally Posted by chrisvarnz
Ooh another problem. What you suggested worked a treat with the edit boxes, is there something special I need to do for 'CComboBox' as CComboBox::SetCurSel is throwing assert errors for me.
In my add dialog, I get the selection made by the user with CComboBox::GetCurSel() which gives me an integer and the whole process is fine, but SetCurSel with the same integer isn't working on initialisation.
Thanks for your help before!
You can only perform actually access the control after windows has created the control. Directly accessing the combo, or any other control, can only be done after the call to CDialog::OnInitDialog() which is called from your own dialog's OnInitDialog() method.
-
May 4th, 2010, 03:33 PM
#6
Re: MFC - How to set value of edit box on initialisation of dialog
Thanks again, VS2008 doesn't generate an OnInitDialog by default in my code, but originally I had a play with it trying to get my original problem to work. Am I to understand then that if I manually define MyDialog::OnInitDialog() and within that make a call to CDialog::OnInitDialog() (kind of like OnOK() makes a call to CDialog::OnOK() to run the non-overridden implementation), I can then within the same definition, change the selection of the combo box? Also assuming that OnInitDialog is run automatically on the call to DoModal.
To avoid asking too many questions in the future, can you point me the direction of some beginners/advanced reference material for MFC, as you clearly know your stuff :P. I've only been using it for a month but I'm getting there.
Thanks!
-
May 4th, 2010, 03:37 PM
#7
Re: MFC - How to set value of edit box on initialisation of dialog
Originally Posted by chrisvarnz
Thanks again, VS2008 doesn't generate an OnInitDialog by default in my code, but originally I had a play with it trying to get my original problem to work. Am I to understand then that if I manually define MyDialog::OnInitDialog() and within that make a call to CDialog::OnInitDialog() (kind of like OnOK() makes a call to CDialog::OnOK() to run the non-overridden implementation), I can then within the same definition, change the selection of the combo box? Also assuming that OnInitDialog is run automatically on the call to DoModal.
To avoid asking too many questions in the future, can you point me the direction of some beginners/advanced reference material for MFC, as you clearly know your stuff :P. I've only been using it for a month but I'm getting there.
Thanks!
There should be some option in 2008 to add OnInitDialog into your class so you don't have to do it yourself. It will add the call to the base class version that actually creates the controls.
I'm not really up on all the latest books. Look for something that's written for VS2008 and MFC if that's what you're using.
Tags for this Thread
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|