Overview
Examples
Screenshots
Comparisons
Applications
Download
Documentation
Tutorials
Bazaar
Status & Roadmap
FAQ
Authors & License
Forums
Funding Ultimate++
Search on this site
Search in forums












SourceForge.net Logo
Home » U++ Library support » ArrayCtrl, HeaderCtrl & GridCtrl » AttrText() and content of the cell
AttrText() and content of the cell [message #11933] Tue, 02 October 2007 21:59 Go to next message
forlano is currently offline  forlano
Messages: 1185
Registered: March 2006
Location: Italy
Senior Contributor
Hello,

I'm using the following code to color the background of a cell
.
marray.Set( r, c, AttrText(txt).Paper(Color(150, 150, 150)));  


I would like to know if this operation modify the content of the cell with respect the following code

marray.Set( r, c, txt);  

From what I'm observing it seems that the content of the cell is not exactly the same. Maybe some invisible character is added by AttrText() that it is passed to display to paint the cell?
Thanks,
Luigi
Re: AttrText() and content of the cell [message #11947 is a reply to message #11933] Wed, 03 October 2007 15:46 Go to previous messageGo to next message
forlano is currently offline  forlano
Messages: 1185
Registered: March 2006
Location: Italy
Senior Contributor
forlano wrote on Tue, 02 October 2007 21:59


From what I'm observing it seems that the content of the cell is not exactly the same. Maybe some invisible character is added by AttrText() that it is passed to display to paint the cell?
Thanks,
Luigi



It is as suspected

#include <CtrlLib/CtrlLib.h>
using namespace Upp;

GUI_APP_MAIN
{ ArrayCtrl arr;
  TopWindow w;
  w.Add(arr);
  arr.SizePos();
  arr.AddColumn("col");
  arr.AddColumn("two");
  arr.Add( 1, 2);
  arr.Add( 1, 2);
  arr.Add( 1, 2);
  
  arr.Set(2,1, AttrText("2").Paper(Color(250,150,150)) );
  arr.Add( 1, arr.Get(2,1) );  //arr.Get(2,1) get not only the number "2" but even some info regarding the color of the cell
  arr.Add( 1, arr.Get(2,1).ToString() );  //I can't get "2"
  arr.Add( 1, AsString(arr.Get(2,1)) );  //I can't get "2"
  
  w.Run();
}


Because AttrText() (both in arrayctrl and gridctrl) extend in some way the data I put inside the cell I would like to know how to extract the data previously inserted in the cell. I mean disregarding the color information and so on. In other words, if I put a number in the cell and then modify its appearence I would like to get back the same number if I need it.

Alternatively I would like to know how to set the background color of a cell indipendently of the content of the cell. If I use Display I can test the passed data, but sometimes would be very useful a direct way to change the background of the cell (i,j) irrispective of the value inside and in a way that it is determined only at runtime.

Luigi

[Updated on: Wed, 03 October 2007 15:48]

Report message to a moderator

Re: AttrText() and content of the cell [message #11948 is a reply to message #11947] Wed, 03 October 2007 16:44 Go to previous messageGo to next message
mrjt is currently offline  mrjt
Messages: 705
Registered: March 2007
Location: London
Contributor
The ArrayCtrl is just returning exactly what you put in - an AttrText - but contained in a Value. You just need to convert it back, though this is more slightly more complicated than for Upp 'native' types:
WString GetText(const Value &v)
{
    return IsTypeRaw<AttrText>(v) ? ValueTo<AttrText>(v).text : WString();
}
James

[Updated on: Wed, 03 October 2007 16:46]

Report message to a moderator

Re: AttrText() and content of the cell [message #11949 is a reply to message #11948] Wed, 03 October 2007 19:01 Go to previous messageGo to next message
forlano is currently offline  forlano
Messages: 1185
Registered: March 2006
Location: Italy
Senior Contributor
mrjt wrote on Wed, 03 October 2007 16:44

The ArrayCtrl is just returning exactly what you put in - an AttrText - but contained in a Value. You just need to convert it back, though this is more slightly more complicated than for Upp 'native' types:
WString GetText(const Value &v)
{
    return IsTypeRaw<AttrText>(v) ? ValueTo<AttrText>(v).text : WString();
}
James


Surprised I missed this trick and I lost many hours finding bugs in improbable places. Everything now work but I needed to modify the previous code as this

String GetText(const Value &v)
{   
    return IsTypeRaw<AttrText>(v) ? ValueTo<AttrText>(v).text.ToString() : (String) v;
}


Thanks!
Luigi
Re: AttrText() and content of the cell [message #11981 is a reply to message #11949] Sat, 06 October 2007 17:46 Go to previous message
mirek is currently offline  mirek
Messages: 13975
Registered: November 2005
Ultimate Member
Actually....

Well, as usually, each simplification tends to backfire...

AttrText was added as simple trick for situations you want to basically use simple visual enchacements and you DO NOT NEED TO READ THE DATA again.

If you do (need to read them), it is better to use custom Display to alter the appearance of displayed Value.

Mirek
Previous Topic: Missing GridCtrl?
Next Topic: desire: ArrayCtrl and GridCtrl: Find in the row
Goto Forum:
  


Current Time: Mon Apr 29 01:28:05 CEST 2024

Total time taken to generate the page: 0.03245 seconds