Solved

Howto update a single edit-field ?

Posted on 2001-08-08
9
289 Views
Last Modified: 2013-11-20
is it possible to make a UpdateData( false ) to a single edit-field ? Cause i wanna update the value of a edit-field every second by a timer. But every time the time makes UpdateData( false ) all changes a user made in an other edit-field are lost.
0
Comment
Question by:DennisWood
  • 5
  • 4
9 Comments
 
LVL 4

Expert Comment

by:captainkirk
ID: 6365805
Just capture the text of the other edit control(s) and call SetWindowText() to restore them...

I don't think you can UpdateData() to just affect one control.
0
 

Author Comment

by:DennisWood
ID: 6365838
How do i capture ? UpdateData( true ) ?
And is SetWindowText pending on single EditField like the following ? So i wouldn't need UpdateData( true ) ?

OnTimer
{
UpdateData();
m_fEditTemp = getTemperature();    // Reads aktual Temperature
((CEdit *)GetDlgItem( IDC_EDIT_TEMP ))->SetWindowText();
}
0
 
LVL 4

Expert Comment

by:captainkirk
ID: 6365887
Use GetWindowText() for each control after you call UpdateData(TRUE), then call SetWindowText() for each control to restore the text.

BTW, UpdateData() should not interfere with the contents of edit controls -- something else must be destroying your data...
0
Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

 

Author Comment

by:DennisWood
ID: 6365928
How do i capture ? UpdateData( true ) ?
And is SetWindowText pending on single EditField like the following ? So i wouldn't need UpdateData( true ) ?

OnTimer
{
UpdateData();
m_fEditTemp = getTemperature();    // Reads aktual Temperature
((CEdit *)GetDlgItem( IDC_EDIT_TEMP ))->SetWindowText();
}
0
 

Author Comment

by:DennisWood
ID: 6365942
ooops
0
 

Author Comment

by:DennisWood
ID: 6365990
the UpdateData( true ) doesn't, the UpdateData( false ) destroys.
The problem is, while a user is typing something into an edit-field, the timer-event occurs, and UpdateData( false ) writes the empy membervaiable into the edit-fields.
for example i have an edit-field IDC_EDIT_KOMMENT connect with the membervariable CString m_sEditKomment. Cause, while the user is editing this field, the membervariable is empty.
I looked into the code and saw that i don't call UpdateData() on Timer intro.
Is it right that GetWindowText() makes the same transfer from EditField to MemberVariable of a specific Control like UpdateData ?
So it would be enough :
OnTimer
{
  // float m_fEditTemp
  m_fEditTemp = getTemperature(); // Sets Temperature
  ((CEdit *)GetDlgItem( IDC_EDIT_TEMP ))->SetWindowText();
   GetDlgItem( IDC_EDIT_TEMP )->RedrawWindow();
}

Sorry i can't test it here. So i have to undestand it.
}
0
 
LVL 4

Accepted Solution

by:
captainkirk earned 100 total points
ID: 6366027
If all you want to do is update text in a specific edit control, then UpdateData(FALSE) is definitely not what you want to do while a user is typing.

The code you provided (with mods) might do the trick:

void CYourClass::OnTimer(UINT nIDEvent)
{
  // float m_fEditTemp
  m_fEditTemp = getTemperature(); // Sets Temperature

  // convert temp to string here...
  CString csTemperature = _T("");
  csTemperature .Format(_T("%.2f"), m_fEditTemp);

  ((CEdit *)GetDlgItem(IDC_EDIT_TEMP))->SetWindowText(csTemperature);
  GetDlgItem( IDC_EDIT_TEMP )->RedrawWindow(); // this might not be needed...
}



0
 

Author Comment

by:DennisWood
ID: 6366055
Thanx a lot for your well nerves ;-) It would be great if you coulld answer nearly so quick the question with html-printing ( question 20165474 ).
0
 
LVL 4

Expert Comment

by:captainkirk
ID: 6366086
thanks....
0

Featured Post

Enterprise Mobility and BYOD For Dummies

Like “For Dummies” books, you can read this in whatever order you choose and learn about mobility and BYOD; and how to put a competitive mobile infrastructure in place. Developed for SMBs and large enterprises alike, you will find helpful use cases, planning, and implementation.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
no14 challenge 14 67
matchUp  challenge 6 62
Use of condition with 'serial' in ansible 2 60
how to split multiple lines delimiter : 8 99
Here is how to use MFC's automatic Radio Button handling in your dialog boxes and forms.  Beginner programmers usually start with a OnClick handler for each radio button and that's just not the right way to go.  MFC has a very cool system for handli…
In this article, I'll describe -- and show pictures of -- some of the significant additions that have been made available to programmers in the MFC Feature Pack for Visual C++ 2008.  These same feature are in the MFC libraries that come with Visual …
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…

773 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question