Codejock Forums Homepage
Forum Home Forum Home > Codejock Products > Visual C++ MFC > Property Grid
  New Posts New Posts RSS Feed - Separating data from display
  FAQ FAQ  Forum Search   Events   Register Register  Login Login

Separating data from display

 Post Reply Post Reply
Author
Message
MacW View Drop Down
Senior Member
Senior Member


Joined: 26 June 2007
Status: Offline
Points: 253
Post Options Post Options   Thanks (0) Thanks(0)   Quote MacW Quote  Post ReplyReply Direct Link To This Post Topic: Separating data from display
    Posted: 29 July 2008 at 5:53am
Hi,

I'd run into a problem with the way the PropertyGrid handles the data storage and display.

For example, I have a value of type double with the value "1234.0056". I can format this as a string and use the SetValue method to display the value in the grid.

The problem is when I use the current users number format settings to format the string, which means that there are only two digits after the comma. The value will then show as "1234.00". When the user now clicks on the edit field to edit the value, this is what he can edit. The .0056 has been lost during the transition.

I keep the original value in a class so I still have access to the 1234.0056, but the way the PropertyGrid works (only SetValue/GetValue from string) does not allow me to hook into the edit cycle.

What I would need is a method which is called when the value of the edit field is about to be set:

virtual void <SomeGridItem>::SetEditText(strValue);

I then could either use the string handed over as the argument, or lookup the "real" value of the item and display this instead.

I looked into the current OnSelect method. I tried to override it, but it uses methods declared as private in the XTP GridItem class.

Is there a way to achieve that?

Back to Top
MacW View Drop Down
Senior Member
Senior Member


Joined: 26 June 2007
Status: Offline
Points: 253
Post Options Post Options   Thanks (0) Thanks(0)   Quote MacW Quote  Post ReplyReply Direct Link To This Post Posted: 29 July 2008 at 6:55am
PS.: Using a custom in-place edit does not help, because the XTP grid calls SetValue before it calls Create, so the edit control does not "know" about which item it belongs to when the SetValue call is made.
Back to Top
mgampi View Drop Down
Senior Member
Senior Member
Avatar

Joined: 14 July 2003
Status: Offline
Points: 1198
Post Options Post Options   Thanks (0) Thanks(0)   Quote mgampi Quote  Post ReplyReply Direct Link To This Post Posted: 29 July 2008 at 9:29am
Hi;

Im using CXTPPropertyGridItemDouble and call SetDoube()/GetDouble() functions. This works very well, because internally the data is really stored as a double value.
You can then work with format strings to change the display of the value.
Martin

Product: Xtreme Toolkit v 19.0.0, new Projects v 19.1.0
Platform: Windows 10 v 1909 (64bit)
Language: VC++ 2017
Back to Top
MacW View Drop Down
Senior Member
Senior Member


Joined: 26 June 2007
Status: Offline
Points: 253
Post Options Post Options   Thanks (0) Thanks(0)   Quote MacW Quote  Post ReplyReply Direct Link To This Post Posted: 29 July 2008 at 2:12pm
Hi,

thanks for the help.
I have my own PropertyGridItem class which can handle the 30+ different data types I support in my grid. The problem is only the mechanism in XTP which handles the "begin edit, end edit" cycle.

When the user clicks a field, the grid takes whatever value is stored inside the m_strValue member of the item. But this contains the formatted string value, which does not necessarily match the real value (e.g. "1234.00" vs. "1234.0054").

I need to somehow override this, to set the edit field from the original value in a potentially different format than the format I use when a field is just displayed. I see no way to do that because XTP uses the same variable to store the formatted display value and to set the edit field when the user begins to edit. Or do I overlook something here?
Back to Top
mgampi View Drop Down
Senior Member
Senior Member
Avatar

Joined: 14 July 2003
Status: Offline
Points: 1198
Post Options Post Options   Thanks (0) Thanks(0)   Quote mgampi Quote  Post ReplyReply Direct Link To This Post Posted: 29 July 2008 at 2:27pm
Hi,

If your using your own item type, why not overwriting the corresponding virtual functions and store/get the data just before/after editing...
Martin

Product: Xtreme Toolkit v 19.0.0, new Projects v 19.1.0
Platform: Windows 10 v 1909 (64bit)
Language: VC++ 2017
Back to Top
MacW View Drop Down
Senior Member
Senior Member


Joined: 26 June 2007
Status: Offline
Points: 253
Post Options Post Options   Thanks (0) Thanks(0)   Quote MacW Quote  Post ReplyReply Direct Link To This Post Posted: 30 July 2008 at 8:12am
Tried that.

But as it seems I would have to override the OnSelect method in the PropertyGridItem.

But because of the way this method is designed and how it calls the Create and SetValue methods, I would need to duplicate the code in the base class. But this is not possible, because the base class relies on members declared as private to PropertyGridItem.

CJ calls SetValue before Create for the inline edit control. Which is wrong for my case. Since the edit control does not know to which item it belongs when SetValue is called, it cannot access the underlying data to access the real value.

But I cannot change this by overriding the OnSelect method because I cannot access the private members CJ uses to calculate the edit window position etc.
Back to Top
 Post Reply Post Reply
  Share Topic   

Forum Jump Forum Permissions View Drop Down

Forum Software by Web Wiz Forums® version 12.04
Copyright ©2001-2021 Web Wiz Ltd.

This page was generated in 0.125 seconds.