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 » Community » Newbie corner » Insert Button into GridCtrl Cell (Can you insert buttons (or any widgets) into gridCtrl?)
Re: Insert Button into GridCtrl Cell [message #59703 is a reply to message #59702] Thu, 09 March 2023 23:40 Go to previous messageGo to previous message
Oblivion is currently offline  Oblivion
Messages: 1215
Registered: August 2007
Senior Contributor
Here's the thing: GridCtrl still uses pre-C++11 callbacks. (Deprecated API)
It should be updated to utilize the new Upp::Function variants and lambda functions with capture...

Good news is that you can achieve -mostly- the same results with the old api calls:

#include <CtrlLib/CtrlLib.h>
#include <GridCtrl/GridCtrl.h>

using namespace Upp;

void ButtonFactory1(One<Ctrl>& c, GridCtrl* list)
{
	static int i = 0;
	String s = list->Get(i++, 0);
	c.Create<Button>()
		.SetLabel(s)
		.WhenAction = [s] { PromptOK("The value is " + s); };
}

struct MyApp : TopWindow {
	GridCtrl  list;
	typedef MyApp CLASSNAME;
	MyApp()
	{
		Sizeable().Zoomable().CenterScreen().SetRect(0, 0, 1024, 800);
		Add(list.SizePos());
		list.AddColumn("texts");
		list.AddColumn("buttons_1").Ctrls(callback1(ButtonFactory1, &list));
		list.AddColumn("buttons_2").Ctrls(THISBACK(ButtonFactory2));
		for(int i = 0; i < 100; i++)
			list.Add(AsString(i), AsString(i));
	
		
	}

	void ButtonFactory2(One<Ctrl>& c)
	{
		static int i = 0;
		String s = list.Get(i++, 0);
		c.Create<Button>()
			.SetLabel(s)
			.WhenAction = [s] { PromptOK("The value is " + s); };
	}

};

GUI_APP_MAIN
{
	MyApp().Run();
}






Best regards,
Oblivion


[Updated on: Thu, 09 March 2023 23:42]

Report message to a moderator

 
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Previous Topic: Choose valid characters for EditString/EditField
Next Topic: Website build
Goto Forum:
  


Current Time: Sat Jul 19 12:30:42 CEST 2025

Total time taken to generate the page: 0.00539 seconds