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 » ArrayCtrl: how activated a callbak by an embedded Option
ArrayCtrl: how activated a callbak by an embedded Option [message #60646] Wed, 19 June 2024 16:28 Go to next message
forlano is currently offline  forlano
Messages: 1207
Registered: March 2006
Location: Italy
Senior Contributor
Hello,

I have un ArrayCtrl and some of its cell contains an Option created with

arr.CreateCtrl<Option>(0, 2, false);

Each time an Option is clicked I need a callback that recognise the row and column where the Option was. The callback is like this:

void MyApp::SetTB()
{  int row = arr.GetClickRow(); 
   if (row<0) return;
   int col = arr.GetClickColumn();
   Exclamation( AsString(row) + " " + AsString(col));
}


Unfortunately, I am not able to achieve this simple task. I tried with no success

arr.WhenSel = THISBACK(SetTB);
arr.WhenCtrlsAction = THISBACK(SetTB);
arr.WhenLeftClick = THISBACK(SetTB);
...

but the associated callback do nothing when I click the Option. It seems the Option shadow the arrayctrl and prevent it to pass the clicked cell. Even the cursor of the arrayCtrl does not move when I click on the Option of fifferent rows.
Instead the callback works when I click a cell whitout the Option.
Perhaps this is a feature. Is there a way to add an Option inside the ArrayCtrl and then pick its coordinate inside the arrayctrl when it is clicked?

Thanks,
Luigi
Re: ArrayCtrl: how activated a callbak by an embedded Option [message #60649 is a reply to message #60646] Thu, 20 June 2024 11:17 Go to previous messageGo to next message
pvictor is currently offline  pvictor
Messages: 75
Registered: December 2015
Member
Hi, Luigi!

Here's a small example:
#include <CtrlLib/CtrlLib.h>

using namespace Upp;

struct Test : TopWindow {
	ArrayCtrl ar;
	
	void AddOption(int row, int col) {
		Option& opt = ar.CreateCtrl<Option>(row,col,false);
		opt << [&,row,col] {
			Exclamation(Sprintf("Row=%d; Col=%d; Status=%d", row, col, opt.Get()));
		};
	}
	
	Test() {
		SetRect(0, 0, 640, 480);
		Add(ar.SizePos());
		ar.AddColumn("Col 1", 1);
		ar.AddColumn("Col 2", 1);
		ar.AddColumn("Col 3", 1);
		for (int i=0; i<10; ++i) ar.Add(i);
		AddOption(0, 1);
		AddOption(1, 2);
		AddOption(2, 1);
		AddOption(3, 2);
		AddOption(4, 1);
		AddOption(5, 2);
		AddOption(6, 1);
		AddOption(7, 2);
	}
};

GUI_APP_MAIN {
	Test().Run();
}


Best regards,
Victor
Re: ArrayCtrl: how activated a callbak by an embedded Option [message #60650 is a reply to message #60649] Thu, 20 June 2024 12:22 Go to previous message
forlano is currently offline  forlano
Messages: 1207
Registered: March 2006
Location: Italy
Senior Contributor
Hi Victor!

thanks a lot for this beautiful example!

I still need to learn how to create ctrls at runtime and attach them a callback.

Best regards,
Luigi
Previous Topic: ArrayCtrl: how to identify embeded Option
Next Topic: Immediate Search correction
Goto Forum:
  


Current Time: Tue Jun 17 13:06:49 CEST 2025

Total time taken to generate the page: 0.03990 seconds