Home » Community » Newbie corner » Insert Button into GridCtrl Cell (Can you insert buttons (or any widgets) into gridCtrl?)
Re: Insert Button into GridCtrl Cell [message #59704 is a reply to message #59702] |
Fri, 10 March 2023 00:10  |
Oblivion
Messages: 1204 Registered: August 2007
|
Senior Contributor |
|
|
Quote:Now the problem is there is no explanation on how to change label or add functionality to individual buttons with the "MakeButton" method
There are several ways, a simple one:
#include <CtrlLib/CtrlLib.h>
#include <GridCtrl/GridCtrl.h>
using namespace Upp;
struct MyButton : Button {
Value val;
MyButton() : Button()
{
WhenAction = [this]
{
PromptOK("The value of the button is " + AsString(val));
};
}
void SetData(const Value& v) override
{
SetLabel(AsString(val = v));
}
Value GetData() const override
{
return val;
}
};
struct MyApp : TopWindow {
GridCtrl list;
MyApp()
{
Sizeable().Zoomable().CenterScreen().SetRect(0, 0, 1024, 800);
Add(list.SizePos());
list.AddColumn("texts");
list.AddColumn("buttons").Ctrls<MyButton>();
for(int i = 0; i < 100; i++)
list.Add(AsString(i), i * 1000);
}
};
GUI_APP_MAIN
{
MyApp().Run();
}
Best regards,
Oblivion
Github page: https://github.com/ismail-yilmaz
upp-components: https://github.com/ismail-yilmaz/upp-components
Bobcat the terminal emulator: https://github.com/ismail-yilmaz/Bobcat
[Updated on: Fri, 10 March 2023 00:26] Report message to a moderator
|
|
|
Goto Forum:
Current Time: Mon Apr 28 10:12:25 CEST 2025
Total time taken to generate the page: 0.00488 seconds
|