Solved

Howto update a single edit-field ?

Posted on 2001-08-08
9
287 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
 

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
IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

 

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

What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

Join & Write a Comment

Suggested Solutions

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 …
Introduction: Load and Save to file, Document-View interaction inside the SDI. Continuing from the second article about sudoku.   Open the project in visual studio. From the class view select CSudokuDoc and double click to open the header …
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.
This demo shows you how to set up the containerized NetScaler CPX with NetScaler Management and Analytics System in a non-routable Mesos/Marathon environment for use with Micro-Services applications.

746 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

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now