How toUpdateData() for a single edit box, not the entire dialog??

  Using VC++ 6 I have created an MFC exe Dialog project. On the Dialog are 
many CEdit edit boxes. I have no problem updating data for the entire dialog, 
but I want to updata for only certain edit boxes at certain times. The 
following code seems like it should work, but it doesn't; it just has no 
effect.

 CEdit* myPoint;
 myPoint=(CEdit*)GetDlgItem(IDC_EDIT2);
 myPoint->UpdateData();

It doesn't matter if it is UpdateData(TRUE) or UpdateData(FALSE).

Similar code to show or hide CStatic texts works just fine.
  CStatic* myPoint;
  myPoint=(CStatic*)GetDlgItem(IDC_STATIC_0);
  myPoint->ShowWindow(SW_HIDE);  

0
junkforme (2)
10/28/2005 8:59:09 PM
vc.mfc 33608 articles. 0 followers. Follow

5 Replies
460 Views

Similar Articles

[PageSpeed] 58

You want to get away from using GetDlgItem. (Can't remember fishes homepage 
address on GetDlgItem???)

Make a control out of the edit box and all other controls on the page.

Not sure what version of studio you are using, but with .NET, right click on
the control
and choose add "Add Variable". Call it something like c_edtName.
Then, you can just use c_edtName.SetWindowText("Some String"); and so on.
It is much easier to do and once you start, you will never go back.
plus, you never have to use UpdateData(TRUE) again.

P.S. It is better to give the ID a better name than IDC_EDIT2

Regards,
"Thor" <junkforme@ev1.net> wrote in message 
news:023817DD-27B8-4E21-8725-E98CBE673289@microsoft.com...
>  Using VC++ 6 I have created an MFC exe Dialog project. On the Dialog are
> many CEdit edit boxes. I have no problem updating data for the entire 
> dialog,
> but I want to updata for only certain edit boxes at certain times. The
> following code seems like it should work, but it doesn't; it just has no
> effect.
>
> CEdit* myPoint;
> myPoint=(CEdit*)GetDlgItem(IDC_EDIT2);
> myPoint->UpdateData();
>
> It doesn't matter if it is UpdateData(TRUE) or UpdateData(FALSE).
>
> Similar code to show or hide CStatic texts works just fine.
>  CStatic* myPoint;
>  myPoint=(CStatic*)GetDlgItem(IDC_STATIC_0);
>  myPoint->ShowWindow(SW_HIDE);
> 


0
chollan2 (126)
10/28/2005 10:10:05 PM
I found the page.

Read this.
http://www.flounder.com/getdlgitem.htm
http://www.codeproject.com/cpp/NoGetDlgItem.asp
essentially the same article.

Regards,
"Computer" <chollan2@san.rr.com> wrote in message 
news:OYs5XxA3FHA.128@tk2msftngp13.phx.gbl...
> You want to get away from using GetDlgItem. (Can't remember fishes 
> homepage address on GetDlgItem???)
>
> Make a control out of the edit box and all other controls on the page.
>
> Not sure what version of studio you are using, but with .NET, right click 
> on
> the control
> and choose add "Add Variable". Call it something like c_edtName.
> Then, you can just use c_edtName.SetWindowText("Some String"); and so on.
> It is much easier to do and once you start, you will never go back.
> plus, you never have to use UpdateData(TRUE) again.
>
> P.S. It is better to give the ID a better name than IDC_EDIT2
>
> Regards,
> "Thor" <junkforme@ev1.net> wrote in message 
> news:023817DD-27B8-4E21-8725-E98CBE673289@microsoft.com...
>>  Using VC++ 6 I have created an MFC exe Dialog project. On the Dialog are
>> many CEdit edit boxes. I have no problem updating data for the entire 
>> dialog,
>> but I want to updata for only certain edit boxes at certain times. The
>> following code seems like it should work, but it doesn't; it just has no
>> effect.
>>
>> CEdit* myPoint;
>> myPoint=(CEdit*)GetDlgItem(IDC_EDIT2);
>> myPoint->UpdateData();
>>
>> It doesn't matter if it is UpdateData(TRUE) or UpdateData(FALSE).
>>
>> Similar code to show or hide CStatic texts works just fine.
>>  CStatic* myPoint;
>>  myPoint=(CStatic*)GetDlgItem(IDC_STATIC_0);
>>  myPoint->ShowWindow(SW_HIDE);
>>
>
> 


0
chollan2 (126)
10/28/2005 10:18:31 PM
On Fri, 28 Oct 2005 13:59:09 -0700, "Thor" <junkforme@ev1.net> wrote:

>  Using VC++ 6 I have created an MFC exe Dialog project. On the Dialog are 
>many CEdit edit boxes. I have no problem updating data for the entire dialog, 
>but I want to updata for only certain edit boxes at certain times. The 
>following code seems like it should work, but it doesn't; it just has no 
>effect.
>
> CEdit* myPoint;
> myPoint=(CEdit*)GetDlgItem(IDC_EDIT2);
> myPoint->UpdateData();
>
>It doesn't matter if it is UpdateData(TRUE) or UpdateData(FALSE).
>
>Similar code to show or hide CStatic texts works just fine.
>  CStatic* myPoint;
>  myPoint=(CStatic*)GetDlgItem(IDC_STATIC_0);
>  myPoint->ShowWindow(SW_HIDE);  

You should use UpdateData only when you want to transfer and validate all
your controls. Otherwise, you should call member functions such as
SetWindowText to update controls. See this message for an explanation of
UpdateData and guidelines on using it:

http://groups-beta.google.com/group/microsoft.public.vc.language/msg/c48f5e455e667a60?hl=en

In addition, you should bind control variables to your controls instead of
using GetDlgItem.

-- 
Doug Harrison
Visual C++ MVP
0
dsh (2498)
10/28/2005 10:26:20 PM
My belief is that UpdateData should never be called.  So I *only* manipulate controls
independently.  SetWindowText and GetWindowText work fine, without the problems of
UpdateData.  Key here is that you should eliminate all instances of GetDlgItem and all
instances of UpdateData from your code.  Note that UpdateData is not a member of CEdit, so
would have no effect.  I'm surprised that code like this would even compile.

See my essays on avoiding GetDlgItem and avoiding UpdateData on my MVP Tips site.

As to why the second one works, it is because it is manipulating the window.  Again, using
GetDlgItem is an exceptionally poor approach here.  On the other hand. in the first
example, at no time did you ever do anything to change the contents of the window.
					joe

On Fri, 28 Oct 2005 13:59:09 -0700, "Thor" <junkforme@ev1.net> wrote:

>  Using VC++ 6 I have created an MFC exe Dialog project. On the Dialog are 
>many CEdit edit boxes. I have no problem updating data for the entire dialog, 
>but I want to updata for only certain edit boxes at certain times. The 
>following code seems like it should work, but it doesn't; it just has no 
>effect.
>
> CEdit* myPoint;
> myPoint=(CEdit*)GetDlgItem(IDC_EDIT2);
> myPoint->UpdateData();
>
>It doesn't matter if it is UpdateData(TRUE) or UpdateData(FALSE).
>
>Similar code to show or hide CStatic texts works just fine.
>  CStatic* myPoint;
>  myPoint=(CStatic*)GetDlgItem(IDC_STATIC_0);
>  myPoint->ShowWindow(SW_HIDE);  
Joseph M. Newcomer [MVP]
email: newcomer@flounder.com
Web: http://www.flounder.com
MVP Tips: http://www.flounder.com/mvp_tips.htm
0
newcomer (15975)
10/29/2005 12:58:03 AM
Hey fish (flounder),

My hard drive crashed, I lost all my stuff. Lost job, Lost freinds, been 
depressed, been drinking, I still am.
I lost your link, and could not remember your name, except that it was a 
fish and had something to do with a fish and avoiding GetDlgItem().

Well, I just wanted to say Hi. Appreciate all the help. No repsonse is 
required or needed.

Regards,
"Joseph M. Newcomer" <newcomer@flounder.com> wrote in message 
news:c2i5m15un519nik27ds7cb06r2l3f9hlhs@4ax.com...
> My belief is that UpdateData should never be called.  So I *only* 
> manipulate controls
> independently.  SetWindowText and GetWindowText work fine, without the 
> problems of
> UpdateData.  Key here is that you should eliminate all instances of 
> GetDlgItem and all
> instances of UpdateData from your code.  Note that UpdateData is not a 
> member of CEdit, so
> would have no effect.  I'm surprised that code like this would even 
> compile.
>
> See my essays on avoiding GetDlgItem and avoiding UpdateData on my MVP 
> Tips site.
>
> As to why the second one works, it is because it is manipulating the 
> window.  Again, using
> GetDlgItem is an exceptionally poor approach here.  On the other hand. in 
> the first
> example, at no time did you ever do anything to change the contents of the 
> window.
> joe
>
> On Fri, 28 Oct 2005 13:59:09 -0700, "Thor" <junkforme@ev1.net> wrote:
>
>>  Using VC++ 6 I have created an MFC exe Dialog project. On the Dialog are
>>many CEdit edit boxes. I have no problem updating data for the entire 
>>dialog,
>>but I want to updata for only certain edit boxes at certain times. The
>>following code seems like it should work, but it doesn't; it just has no
>>effect.
>>
>> CEdit* myPoint;
>> myPoint=(CEdit*)GetDlgItem(IDC_EDIT2);
>> myPoint->UpdateData();
>>
>>It doesn't matter if it is UpdateData(TRUE) or UpdateData(FALSE).
>>
>>Similar code to show or hide CStatic texts works just fine.
>>  CStatic* myPoint;
>>  myPoint=(CStatic*)GetDlgItem(IDC_STATIC_0);
>>  myPoint->ShowWindow(SW_HIDE);
> Joseph M. Newcomer [MVP]
> email: newcomer@flounder.com
> Web: http://www.flounder.com
> MVP Tips: http://www.flounder.com/mvp_tips.htm 


0
chollan2 (126)
10/29/2005 1:23:07 AM
Reply:

Similar Artilces:

upgrading the OS on Exch2003 box
I have successfully upgraded Exch2000 to 2003. The OS is still Windows 2000 Server. Now I'm ready to upgrade that box to Windows Server 2003. Is there anything special I should note before upgrading, or is there a specific document which addresses any known method or problems ? thanks chrism "chrism" <chris@no_spam> wrote: >I have successfully upgraded Exch2000 to 2003. >The OS is still Windows 2000 Server. > >Now I'm ready to upgrade that box to Windows Server 2003. > >Is there anything special I should note before upgrading, or is there >a...

RPC over HTTP/S on Exchange 2003
I have been configuring my single server with exchange to use RPC over https I have followed the instructions in MS guide and another simplified guide at http://www.petri.co.il/configure_rpc_over_https_on_a_single_server.htm Server spec is: Server 2003 standard SP1, Exchange 2003 SP1, XP client SP2 with outlook 2003 sp2 The bottom line is that when testing from the WAN, the outlook client will not connect and say that the exchange server is unavailable. I have a lot of experience configuring rpc over http/s with sbs2003 but this is the first time for server 2003 standard. I have outlook ...

How to increase an entire collumn by a certain percentage?
I have a collumn of dollar amounts that I want to increase by a certain mulaplier, say 35%. Is there any way to do this? The collumns are on average 30 rows long, with various amounts. In an empty cell somewhere type 1.35 (for 35%). Then do the following: 1. Select and copy that cell with 1.35 in it 2. Then select the column of numbers that you want increased by 35% 3. Click Edit/Paste Special 4. Under Paste, select "Formulas" 5. Under Operation, select "Multiply" 6. Click OK "Josh" wrote: > I have a collumn of dollar amounts that I want to increa...

NTBackup / No Entires Found
NTbackup says it successfully backs up the Information Store\First Storage Group and SRS\ SRS Storage. But when going to "Restore and Manage Media", select the tape media, under log files, Mailbox Store and Public folder Store, they all show "No entries found". Thoughts? You just select those objects. Restoring part of an Exchange backup (just a database or some logs) wouldn't work and thus I guess its just trying to prevent that. -- Hope that helps, Dan Townsend This posting is provided "AS IS" with no warranties, and confers no rights. Please do not...

Keeping a table in a form editable and checking that fields are filled in before allowing a save
Firstly apologies if this is the incorrect forum but I was looking for a general word forum and could not find one. Please point me to one if one exists. I am trying to create a form where I want to specify what items need to be filled in. (Review minutes from design reviews). I want to make certain fields mandatory like the date, attendees and check list used and want to block saving of the document with a warning until they are filled in. Is there a way of doing this? Also as a part of the review actions are filled in to a table. depending on how many actions there are the table...

How to write a new entry in a combo box to its underlying table
Dear Access 2007 VBA Gurus, I have a assets database (rather uncreatively named "Assets"). I use a form (named "Asset Acquisition Input Form New") to enter new assets. The "Manufacturer" field (combo box name "Manufacturers_ID) on this form is a lookup to a Manufacturers table. What I want to happen is when I enter an item that is not in the lookup list, I want a message box to prompt me to add the new entry to the underlying table, or to cancel and select an item from the list. I have no trouble with the MsgBox command itself. What I don&...

Right click in Pivot Table or on Entire Column
I have added items to the right-click menu that popups up when you have a cell or cells selected. But when you are in a Pivot Table or have an entire column selected the right-click popup is different. Is there a way to add an item to the right-click popup menu when you are in a Pivot Table or have an entire column selected? Thank you for your help. Steven Never mind. This one was right in the help section. I should have looked first. Thank you, Steven "Steven" wrote: > I have added items to the right-click menu that popups up when you have a ...

Convert Double Space To Single Space
How do you convert double spaced text to single spaced? I don't see an option for this in Outlook. I can paste into Notepad, copy and then paste into Outlook, but I would prefer a way to do it within Outlook. ...

E-mail box sizes. Echange System Manger.
Hi. Now and then I need to find out the size of the various e-mail boxes in Exchange2000. The problem is that the size indicated in the Exchange System Manager do not reflect the same size when you look into Outlook. Is the a way to figure out the correct e-mail size? If not. Is this better in Exchange2003? Thank you in advance. DagN I'd consider the Exchange value to be the most important given this is what will be used for mailbox quotas, etc. Nue "Dag N" <skier@start.no> wrote in message news:OjCaWfjLGHA.2320@TK2MSFTNGP11.phx.gbl... > Hi. > Now and then ...

[ANN] "Bend Word to your Will" -- April 2005 edition free download
Dear all, THIS ANNOUNCEMENT IS ABOUT A *NON-COMMERCIAL* RESOURCE BASED IN PART ON ACCUMULATED ADVICE FROM THIS NEWSGROUP The latest version of my notes on Word -- titled "Bend Word to Your Will" -- is now available for downloading from the Word MVPs' site, http://www.mvps.org/word/FAQs/WordMac/Bend/BendWord.htm WHAT IS "BEND WORD TO YOUR WILL"? "Bend Word to Your Will" is not a commercial product for sale -- it's free. It's a dictionary-style (mainly) set of notes on Word that I've been continually adding to and polishing for the past four year...

How to return the primary key from a combo box
I have a table containing two columns Column 1: Primary key Column 2: Name. I want to create an unbound combo box that shows the name but returns the PK. I have these properties set: Control source: <is empty> Row source type: table/query Bound column: 1 Row source: <I have a select that returns the desired records> In cboClient_AfterUpdate() I look at debug.print cboClient.Value and I see the name. I need the PK so I can construct the query for the next combo box. How do I get the PK Thanks for the help -- Message posted via http://www.accessmons...

Simple Yes/No drop down box
Hi, I am looking to create a simple drop down box which has yes or no as the options. For the life of me i can't remember how to do it. Thanks Select the cell and then click on Data | Data Validation. In the dialogue box for Allow click on List, and then in Source you can type "Yes,No" (without the quotes) and ensure that In-cell drop-down is checked. Click OK and then you have it. Hope this helps. Pete On Apr 21, 9:41=A0am, Debi <D...@discussions.microsoft.com> wrote: > Hi, I am looking to create a simple drop down box which has yes or no as = the ...

creating nested formulas from drop down box
Hi, I have cell A1 with a drop down box containing 26 available choices. B1 has the dollar amount matching to the choice in A1 using vlookup. E1 totals several cells including B1 together. I want F1 to look at A1 and either enter the number from E1 or NA. Here's billing example: A1=January , B1=$5 ,C1=$10, D1=$1, E1=$16 (total of b-d1) F1 is the column for January G1 is the column for February H1 is the column for March, etc If A1 = Jan, then F1 should be $16 If A1 = Feb, then F1 should be NA or $0 This is the formula that has been working so far: =IF((G2="...

font change when editing
I have this I can place on the sheet module to change font when editing. Is there a way to put this into a macro so I can enter this into the sheet automatically each time I am emailed a new version of the workbook? Thanks. Private Sub Worksheet_Change(ByVal Target As Range) Target.Cells.Interior.ColorIndex = 4 End Sub ...

anchor picture to text box
(Publisher 2003) I have a newsletter with a Kudos box. In the corners of the box I have a happy face. I'd like the happy faces to be anchored to their corners so when I enlarge or shorten the box, the faces move along with the text box. Why not create a rectangle, insert the happy faces, group. The problem as I see it would be if you resize, the happy faces could be distorted if you widen or shrink the group. You would always have to re-size proportionally. -- Mary Sauer http://msauer.mvps.org/ "Helen" <Helen@discussions.microsoft.com> wrote in message news:193...

Creating Dialog Pointer with new, causes Exception
Hello all, I've written an MFC app, which has a tabbed interface. When it starts up, it checks my registry key, to determine how many tabs it needs, it then creates each tab, and puts a custom non modal, child dialog on each tab. The problem is, in release mode, it can only create the first dialog, the second one causes a memory exception. It *looks* like MFC doesnt like me trying to initialize a pointer like so, when that pointer is NULL. m_pDialogs[i] = new CMyDialog; Thing is, isn't that the whole point of the new operator? And malloc for that matter? The only difference, th...

"Enabel / Disable macros" message box appears no matter which .xls file the user opens....
"Enabel / Disable macros" message box appears no matter which .xls file I open... I can't find any hidden/empty code in the xls files... Has someone got any experience with this? krgds, Nils Egil Lie Stolt Offshore AS Hi you also have to remove the (empty) modules in the VBA editor. Also check that there're no statements left in the worksheet modules and in the workbook module -- Regards Frank Kabel Frankfurt, Germany Nils Egil Lie wrote: > "Enabel / Disable macros" message box appears no matter which .xls > file I open... I can't find any hidden/emp...

Cannot Edit Charts in PPT2007
Problem: I cannot edit Charts after they are created and save. When I click on the Edit for the chart, task manager indicates the EXCEL.EXE task is launched, but the worksheet does not appear. When creating a new presentation and a new chart, everything works the way it should. After saving the presentation, Its broken? This must be some sort of Registry setting, I've re-installed Office 2007 Standard, run Diagnostics, all to no avail. The Same saved presentation works properly on another PCs Powerpoint 2007 in the same office. Have you installed SP2 for Office 2007? -- ...

text box email publication
I am a publisher novice. I am trying to develop an e-mail newletter. The templates in publisher have a text box under each article with what appears to be a hyperlink with "more details". I assume this will enable the reader of the email to expand the text box and see the full details of the article. I like this feature as it means that readers only get to see the title and abstract and then can select the articles they want to read in full. Unfortunately I can not work out how to use this function and as usual help is no help. Tim no such feature in Publisher. "kiwi ti...

Problem Editing Transfer IN/OUT after HQ Xfer created
If I create the Transfer from Store1 -> Store 2 in HQ, I can edit the quantities in Store 1 after the xfer is created via Style 330. Question: Will my edits in Store 1 be visible in Store 2? If so, what is the procedure for doing so? David My question might be a little confusing. If I use Style 330 to create an X-fer from Store 1 -> Store 2, I can still edit the POs. Note: I run 401 before running 330. If I go into SO Mgr for Store 1, I can edit the TO, but my edits don't synchronize with Store 2 - this is after I ran a 401. Why? Is this a limitation of RMS? How do I edi...

edit a drop down list
Hello, I have 2 questions 1. for an existing drop down list, how can I add a new entry? That is, a list named "division" now contains 5 items, and I want to add a sixth. I've tried to highlight all 6 items and typing "division" into the name box, but that just jumps me to the original 5 names. I also tried highlighting the original 5 and deleting the "division" from the name box, but again no luck. 2. Can I enlarge the font on a drop down list, so it appears larger when the arrow is clicked? The font is very small at present. To change the name r...

File Open Box
When I go file open and the box appears to select where & what I want to open, it appears full screen, how can I reduce the size of it (it never used to be full screen). I try placing the mouse on the edges but it won't give me a drag arrow from anywhere around the perimeter of the screen Drove me near insane once. Dbl-click in the dialog title bar. "bev" <bev@discussions.microsoft.com> wrote in message news:66C4FC65-041A-4EF3-A1F0-4B1FEA6F472F@microsoft.com... > When I go file open and the box appears to select where & what I want to > open...

xml edit #2
I am trying to edit an xml receipt in notepad..whenever I try to save I can't save as a xml file ..it wants to save as a text file..How can I save as a xml file? -- billr You can just change the extension manually after you save it. Example - File saves as "report.txt" Rename it to "report.xml" and that's all there is to it. Billr, Try doing a Ctrl+S to save it. It should save it as the name it opened. Are you using a Notepad replacement program? Help | About | should say "Microsoft Notepad" -- * Get Secure! - www.microsoft.com/security Yo...

Password not remembered even though I've followed Microsoft's Registry edit....
Hello I have outlook 2003 and the password is not being remembered when I check email. I have followed Microsoft's instructions to edit the registry and remove the keys from the Protected Storage System provider but this has not helped. I am at a loss as I can't find any other information on this. I would appreciate any help. Thank you Jawaz Same thing happened to me. (XP prof + Outlook 2003). About 3 months ago the MS edit registry worked but the problem has cropped up again within the past 2 weeks. Appeared to coinside with the New Yahoo Mail change. Could it be related ...

Want to modify this procedure to have a range of periods rather than a single period
This is a multi-part message in MIME format. ------=_NextPart_000_00BF_01CB206B.89E3AC60 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable I have the procedure below I want simply modify the periods procedure below to be -- perpost >=3D = '201001' and <=3D '201012' so I want a range of periods rather than a = single period as in the example below I would really appreciate it if someone can help me out on this. Thanks=20 Sammy USE DEMOAPP Declare @perpost nvarchar(8) /* Do not edit Above=20 ...