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 » how to set/get data in a composite embedded ctrl in an arrayctrl
how to set/get data in a composite embedded ctrl in an arrayctrl [message #3076] Sat, 06 May 2006 02:06 Go to next message
forlano is currently offline  forlano
Messages: 1185
Registered: March 2006
Location: Italy
Senior Contributor
Hello,

here is a new variant of a code already posted in this forum. We have an arrayctrl with two column of which the second one contains a composite embedded ctrl (editint+label). The click on the button start the scan of the rows to get their value.
I would like to get some hint for the followomg tasks:
1. how to GET the data of editint in row 'i' ;
2. how to SET the data of editint in row 'i' ;

I am able to perform this task in case of a single control in the cell but with two in the cell I'm lost Smile .
Thank you
Luigi

#include <CtrlLib/CtrlLib.h>

#define LAYOUTFILE    <edithelp/a.lay>
#include <CtrlCore/lay.h>

//--------------------- begin class -----------------
class EditLabel : public WithEditLabel<TopWindow> {
public:
	typedef EditLabel CLASSNAME;
	void WriteLabel();
	EditLabel();
};

void EditLabel::WriteLabel()
{	lbl.SetLabel( AsString(~edit) );
	SetFocus();
}

EditLabel::EditLabel()
{	CtrlLayout(*this, "");
	edit <<= THISBACK(WriteLabel);
}

void Extra2(One<Ctrl>& ctrl)
{	ctrl.Create<EditLabel>();
}
//--------------------- end class -------------------

ArrayCtrl arr;
void getvaluearray()
{ for(int i=0; i<arr.GetCount(); i++)
  { Exclamation( AsString ( arr.Get(i, 0) ) ); // get data in column 0
    // how to get the editint value in column 1?
  }
	
}
GUI_APP_MAIN
{
	TopWindow w;

	Button btn;
	
	arr.AddColumn("col1",20);
	arr.AddColumn("col2",20).Ctrls(Extra2);
	arr.SetLineCy(20);
		
	arr.Add("aaa");
	arr.Add("bbb");
	arr.Add("ccc");
	arr.SizePos();
	w.Add(arr);
	w.Add(btn);
	btn.SetLabel("Get data").LeftPosZ(72, 116).TopPosZ(292, 20);
	btn.WhenAction = callback(getvaluearray);
	w.Run();
}

LAYOUT(EditLabel, 96, 19)
	ITEM(EditInt, edit, LeftPosZ(2, 32).TopPosZ(1, 17))
	ITEM(Label, lbl, SetFrame(ThinInsetFrame()).LeftPosZ(36, 60).TopPosZ(1, 17))
END_LAYOUT

[Updated on: Sat, 06 May 2006 02:06]

Report message to a moderator

Re: how to set/get data in a composite embedded ctrl in an arrayctrl [message #3078 is a reply to message #3076] Sat, 06 May 2006 02:35 Go to previous messageGo to next message
fudadmin is currently offline  fudadmin
Messages: 1321
Registered: November 2005
Location: Kaunas, Lithuania
Ultimate Contributor
Administrator
I'm nearly sleeping, so my answer might not be very sound. But I in your place would look at something like GetFirstChild or LastChild, or GetNext...
Re: how to set/get data in a composite embedded ctrl in an arrayctrl [message #3081 is a reply to message #3078] Sat, 06 May 2006 03:59 Go to previous messageGo to next message
fudadmin is currently offline  fudadmin
Messages: 1321
Registered: November 2005
Location: Kaunas, Lithuania
Ultimate Contributor
Administrator
fudadmin wrote on Sat, 06 May 2006 01:35

I'm nearly sleeping, so my answer might not be very sound. But I in your place would look at something like GetFirstChild or LastChild, or GetNext...


No, windows experience doesn't work here for me.
And unfortunately, I think, in this area U++ is ...<my famous fraze>...
But, we'll see.
Re: how to set/get data in a composite embedded ctrl in an arrayctrl [message #3082 is a reply to message #3076] Sat, 06 May 2006 07:02 Go to previous messageGo to next message
mirek is currently offline  mirek
Messages: 13975
Registered: November 2005
Ultimate Member
forlano wrote on Fri, 05 May 2006 20:06

Hello,

here is a new variant of a code already posted in this forum. We have an arrayctrl with two column of which the second one contains a composite embedded ctrl (editint+label). The click on the button start the scan of the rows to get their value.
I would like to get some hint for the followomg tasks:
1. how to GET the data of editint in row 'i' ;
2. how to SET the data of editint in row 'i' ;

I am able to perform this task in case of a single control in the cell but with two in the cell I'm lost Smile .
Thank you
Luigi

#include <CtrlLib/CtrlLib.h>

#define LAYOUTFILE    <edithelp/a.lay>
#include <CtrlCore/lay.h>

//--------------------- begin class -----------------
class EditLabel : public WithEditLabel<TopWindow> {
public:
	typedef EditLabel CLASSNAME;
	void WriteLabel();
	EditLabel();
};

void EditLabel::WriteLabel()
{	lbl.SetLabel( AsString(~edit) );
	SetFocus();
}

EditLabel::EditLabel()
{	CtrlLayout(*this, "");
	edit <<= THISBACK(WriteLabel);
}

void Extra2(One<Ctrl>& ctrl)
{	ctrl.Create<EditLabel>();
}
//--------------------- end class -------------------

ArrayCtrl arr;
void getvaluearray()
{ for(int i=0; i<arr.GetCount(); i++)
  { Exclamation( AsString ( arr.Get(i, 0) ) ); // get data in column 0
    // how to get the editint value in column 1?
  }
	
}
GUI_APP_MAIN
{
	TopWindow w;

	Button btn;
	
	arr.AddColumn("col1",20);
	arr.AddColumn("col2",20).Ctrls(Extra2);
	arr.SetLineCy(20);
		
	arr.Add("aaa");
	arr.Add("bbb");
	arr.Add("ccc");
	arr.SizePos();
	w.Add(arr);
	w.Add(btn);
	btn.SetLabel("Get data").LeftPosZ(72, 116).TopPosZ(292, 20);
	btn.WhenAction = callback(getvaluearray);
	w.Run();
}

LAYOUT(EditLabel, 96, 19)
	ITEM(EditInt, edit, LeftPosZ(2, 32).TopPosZ(1, 17))
	ITEM(Label, lbl, SetFrame(ThinInsetFrame()).LeftPosZ(36, 60).TopPosZ(1, 17))
END_LAYOUT



Hopefuly, despite Aris' despect, this time U++ is ortogonal:

To get/set Value, you use "SetData"/"GetData". The same applies to composite Ctrl, just in this case you will need more than single Value. The solution is ValueArray which can pack more Values into single value. Therefore:

void MyCompositeCtrl::SetData(const Value& v)
{
   ValueArray va = v;
   myintedit <<= va[0];
   mytextedit <<= va[1];
....
}

....
ValueArray va;
va.Add(1);
va.Add("Hello");
arrayctrl.Set(1, 1, va);



Mirek
Re: how to set/get data in a composite embedded ctrl in an arrayctrl [message #3083 is a reply to message #3082] Sat, 06 May 2006 07:04 Go to previous messageGo to next message
mirek is currently offline  mirek
Messages: 13975
Registered: November 2005
Ultimate Member
P.S.: Now seing your post, your situation is much more simple, as you have just single child Ctrl... In that case you do not need ValueArray, just implement SetData to use single value to set single child Ctrl...

Mirek
Re: how to set/get data in a composite embedded ctrl in an arrayctrl [message #3089 is a reply to message #3083] Sat, 06 May 2006 13:32 Go to previous messageGo to next message
forlano is currently offline  forlano
Messages: 1185
Registered: March 2006
Location: Italy
Senior Contributor
luzr wrote on Sat, 06 May 2006 07:04

P.S.: Now seing your post, your situation is much more simple, as you have just single child Ctrl... In that case you do not need ValueArray, just implement SetData to use single value to set single child Ctrl...

Mirek


Mirek,
I'm sorry but I was unable to catch what to do.
Anyway, I miss a method that permit me to get the object in a cell. The object could be a simply edit, or a composite widget (for example editstring+editint+label+...) defined as class somewhere else with/without the help of layout. Then with something like
child = array.GetCtrlCell(row, col);
I would get in my hand whatever is inside the cell and start to do with it (by 'child.objectspecificproperty() ) any weird thing i like... get data, set data,..., and expecially set the focus where I want so that I can stop to fight with this lazy array cursor that do not follow the click on the embedded ctrl. This seems to me much simpler and after it the array would stop to be an headcache (for me Smile ) for some more complex task... but of course I am unaware of the all exisisting methods that perhaps are even easier.
At the moment I feel to deal with the arrayctrl in somehow too complex or at least not immediate way when the cell contains not a static data to be set/get. This contrast a lot with the amazing simplicity of all the remaining ctrls and tools available in U++.

Luigi
Re: how to set/get data in a composite embedded ctrl in an arrayctrl [message #3112 is a reply to message #3089] Sun, 07 May 2006 19:57 Go to previous messageGo to next message
mirek is currently offline  mirek
Messages: 13975
Registered: November 2005
Ultimate Member
forlano wrote on Sat, 06 May 2006 07:32

luzr wrote on Sat, 06 May 2006 07:04

P.S.: Now seing your post, your situation is much more simple, as you have just single child Ctrl... In that case you do not need ValueArray, just implement SetData to use single value to set single child Ctrl...

Mirek


Mirek,
I'm sorry but I was unable to catch what to do.
Anyway, I miss a method that permit me to get the object in a cell. The object could be a simply edit, or a composite widget (for example editstring+editint+label+...) defined as class somewhere else with/without the help of layout. Then with something like
child = array.GetCtrlCell(row, col);
I would get in my hand whatever is inside the cell and start to do with it (by 'child.objectspecificproperty() ) any weird thing i like... get data, set data,..., and expecially set the focus where I want so that I can stop to fight with this lazy array cursor that do not follow the click on the embedded ctrl. This seems to me much simpler and after it the array would stop to be an headcache (for me Smile ) for some more complex task... but of course I am unaware of the all exisisting methods that perhaps are even easier.
At the moment I feel to deal with the arrayctrl in somehow too complex or at least not immediate way when the cell contains not a static data to be set/get. This contrast a lot with the amazing simplicity of all the remaining ctrls and tools available in U++.

Luigi



Actually, this is most likely caused by the fact that ability to have "embedded" Ctrls is very recent, means this part is not as matured. In fact, I was thinking about "GetCellCtrl" for some time now, for similar reasons.

The only not very elegant issue is that such function will require to return generic "Ctrl *", requiring downcast.....

Mirek
Re: how to set/get data in a composite embedded ctrl in an arrayctrl [message #3116 is a reply to message #3112] Sun, 07 May 2006 21:52 Go to previous messageGo to next message
forlano is currently offline  forlano
Messages: 1185
Registered: March 2006
Location: Italy
Senior Contributor
luzr wrote on Sun, 07 May 2006 19:57


Actually, this is most likely caused by the fact that ability to have "embedded" Ctrls is very recent, means this part is not as matured. In fact, I was thinking about "GetCellCtrl" for some time now, for similar reasons.

The only not very elegant issue is that such function will require to return generic "Ctrl *", requiring downcast.....

Mirek

I think that the elegance can stay at second place if one can dispose of such powerful method that resolve many (all?) kind of problems with embedded ctrl. With it I could resolve in a snap the problems I signaled in other threads regarding the arrayctrl. Moreover please consider that it should be used in complex task so that the developer should be ready to pay in term of decrease of elegance this additional "weapon" that simplify his life.

Luigi
Re: how to set/get data in a composite embedded ctrl in an arrayctrl [message #3118 is a reply to message #3116] Sun, 07 May 2006 22:06 Go to previous message
mirek is currently offline  mirek
Messages: 13975
Registered: November 2005
Ultimate Member
Quote:


I think that the elegance can stay at second place if one can dispose of such powerful method that resolve many (all?) kind of problems with embedded ctrl.



Yes, the only problem is that sometimes there exists elegant solution...

E.g. in this case, other interface solution I am considering is to alternatively pass

Array<T>

to the "Ctrls" method,

void Ctrls<T>(Array<T>& ctrls);

so that ArrayCtrl would create its stuff in the place you have "external" access to. This way, downcasts would not be necessary.

OTOH, current inteface cannot be now removed (that is why I am always afraid when creating new stuff....), so Ctrl *GetCtrl method addition is very likely...

Mirek
Previous Topic: ArrayCtrl cell consisting of edit and helper button
Next Topic: ArrayCtrl cell color
Goto Forum:
  


Current Time: Mon Apr 29 10:11:56 CEST 2024

Total time taken to generate the page: 0.02543 seconds