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 |
|
forlano
Messages: 1189 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 .
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 #3082 is a reply to message #3076] |
Sat, 06 May 2006 07:02 |
|
mirek
Messages: 13984 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 .
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 #3089 is a reply to message #3083] |
Sat, 06 May 2006 13:32 |
|
forlano
Messages: 1189 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 ) 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 |
|
mirek
Messages: 13984 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 ) 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
|
|
|
|
|
Goto Forum:
Current Time: Mon Jun 10 13:14:40 CEST 2024
Total time taken to generate the page: 0.01640 seconds
|