Separating data from display |
Post Reply |
Author | |
MacW
Senior Member Joined: 26 June 2007 Status: Offline Points: 253 |
Post Options
Thanks(0)
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? |
|
MacW
Senior Member Joined: 26 June 2007 Status: Offline Points: 253 |
Post Options
Thanks(0)
|
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.
|
|
mgampi
Senior Member Joined: 14 July 2003 Status: Offline Points: 1201 |
Post Options
Thanks(0)
|
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 22.1.0, new Projects v 24.0.0 Platform: Windows 10 v 22H2 (64bit) Language: VC++ 2022 |
|
MacW
Senior Member Joined: 26 June 2007 Status: Offline Points: 253 |
Post Options
Thanks(0)
|
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? |
|
mgampi
Senior Member Joined: 14 July 2003 Status: Offline Points: 1201 |
Post Options
Thanks(0)
|
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 22.1.0, new Projects v 24.0.0 Platform: Windows 10 v 22H2 (64bit) Language: VC++ 2022 |
|
MacW
Senior Member Joined: 26 June 2007 Status: Offline Points: 253 |
Post Options
Thanks(0)
|
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. |
|
Post Reply | |
Tweet
|
Forum Jump | Forum Permissions You cannot post new topics in this forum You cannot reply to topics in this forum You cannot delete your posts in this forum You cannot edit your posts in this forum You cannot create polls in this forum You cannot vote in polls in this forum |