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 create a Ctrl on selection? (Creating Ctrls for every column makes the program VERY slow so I prefer doing it just on the selected cell)
How to create a Ctrl on selection? [message #52572] Tue, 22 October 2019 16:15 Go to next message
SidusBrist is currently offline  SidusBrist
Messages: 4
Registered: October 2019
Junior Member
Hi,
I'm making an excel-like program.
I have an ArrayCtrl with dynamic columns and I wanted to add Ctrls so that you can edit the content.

I was trying to add them by default for every column, so I made this:

if (f.isAlpha){
	table.ColumnAt(table.GetColumnCount()-1).Ctrls<EditString>();
}
else {
	if (f.nDecimals>0){
		table.ColumnAt(table.GetColumnCount()-1).Ctrls<EditDouble>();
	}
	else {
		table.ColumnAt(table.GetColumnCount()-1).Ctrls<EditInt>();
	}
}


Unfortunately it's very slow, both the loading of the table and the program itself once it's loaded.
So I had an idea... When you click on a cell, it creates the edit just for that cell and if you click outside or press "enter" it destroys itself and the new value is updated.

The question is... how can I do this? Shocked
Re: How to create a Ctrl on selection? [message #52586 is a reply to message #52572] Thu, 24 October 2019 13:25 Go to previous messageGo to next message
mirek is currently offline  mirek
Messages: 12105
Registered: November 2005
Ultimate Member
Using Edit:

https://www.ultimatepp.org/reference$ArrayCtrlEdits$en-us.ht ml

(in this example, check the first column).
Re: How to create a Ctrl on selection? [message #52587 is a reply to message #52586] Thu, 24 October 2019 14:32 Go to previous messageGo to next message
SidusBrist is currently offline  SidusBrist
Messages: 4
Registered: October 2019
Junior Member
I tried but nothing happens... I click on the row but the box doesn't appear Sad

table.AddRowNumColumn(" ",45);
table.ColumnAt(0).SetDisplay(Single<WhiteFill>());
std::ifstream infile(pb);
std::string line;
while (std::getline(infile, line))
{
	std::istringstream iss(line);
	CobolField f(line.c_str());
	if (f.isField){
		fields.push_back(f);
		std::string columnDescription = "Da " + std::to_string(f.start+1) + " a " + std::to_string(f.end) + " per " + std::to_string(f.size) + " byte";
		if (f.shortenedName!="FILLER"){
			table.AddColumn(f.shortenedName,120);
		}
		else {
			table.AddColumn(f.shortenedName,40);
			table.HeaderTab(table.GetColumnCount()-1).SetInk(Color(196,196,196));
		}
		if (f.isK001){
			Font font = table.HeaderTab(table.GetColumnCount()-1).GetFont();
			font.Underline(true);
			table.HeaderTab(table.GetColumnCount()-1).SetFont(font);
		}
		table.ColumnAt(table.GetColumnCount()-1).Tip(columnDescription.c_str());
		if (f.isAlpha){
			table.ColumnAt(table.GetColumnCount()-1).Edit(editString);
		}
		else {
			if (f.nDecimals>0){
				table.ColumnAt(table.GetColumnCount()-1).Edit(editDouble);
			}
			else {
				table.ColumnAt(table.GetColumnCount()-1).Edit(editInt);
			}
		}
		table.Appending().Removing().Duplicating();
		CobolField::fieldStart = CobolField::fieldStart + f.size;
	}
	if (f.isXSYS){
		break;
	}
}
table.SetLineCy(EditField::GetStdHeight());


P.S.: I just realized "AddColumn" returns the column so I don't need to always use table.ColumnAt()...
Re: How to create a Ctrl on selection? [message #52588 is a reply to message #52587] Thu, 24 October 2019 19:33 Go to previous messageGo to next message
mirek is currently offline  mirek
Messages: 12105
Registered: November 2005
Ultimate Member
SidusBrist wrote on Thu, 24 October 2019 14:32
I tried but nothing happens... I click on the row but the box doesn't appear Sad

table.AddRowNumColumn(" ",45);
table.ColumnAt(0).SetDisplay(Single<WhiteFill>());
std::ifstream infile(pb);
std::string line;
while (std::getline(infile, line))
{
	std::istringstream iss(line);
	CobolField f(line.c_str());
	if (f.isField){
		fields.push_back(f);
		std::string columnDescription = "Da " + std::to_string(f.start+1) + " a " + std::to_string(f.end) + " per " + std::to_string(f.size) + " byte";
		if (f.shortenedName!="FILLER"){
			table.AddColumn(f.shortenedName,120);
		}
		else {
			table.AddColumn(f.shortenedName,40);
			table.HeaderTab(table.GetColumnCount()-1).SetInk(Color(196,196,196));
		}
		if (f.isK001){
			Font font = table.HeaderTab(table.GetColumnCount()-1).GetFont();
			font.Underline(true);
			table.HeaderTab(table.GetColumnCount()-1).SetFont(font);
		}
		table.ColumnAt(table.GetColumnCount()-1).Tip(columnDescription.c_str());
		if (f.isAlpha){
			table.ColumnAt(table.GetColumnCount()-1).Edit(editString);
		}
		else {
			if (f.nDecimals>0){
				table.ColumnAt(table.GetColumnCount()-1).Edit(editDouble);
			}
			else {
				table.ColumnAt(table.GetColumnCount()-1).Edit(editInt);
			}
		}
		table.Appending().Removing().Duplicating();
		CobolField::fieldStart = CobolField::fieldStart + f.size;
	}
	if (f.isXSYS){
		break;
	}
}
table.SetLineCy(EditField::GetStdHeight());


P.S.: I just realized "AddColumn" returns the column so I don't need to always use table.ColumnAt()...


Hard to say from this snippet. How and _where_ is 'editDouble' defined? Note that it must exist through the lifetime of ArrayCtrl.

Mirek
Re: How to create a Ctrl on selection? [message #52593 is a reply to message #52588] Fri, 25 October 2019 09:29 Go to previous messageGo to next message
SidusBrist is currently offline  SidusBrist
Messages: 4
Registered: October 2019
Junior Member
Actually I declare them before that piece of code, inside the function, if I make a public variable it kinda works (it clones the input on every column). I'll post the whole script so I don't need to write an huge post.
The problem is that they are not "static" so I can't create 20 single variables for every type... I need something dynamic with pointers and slicing, while Edit function doesn't want them...

Quote:
error: no matching function for call to 'Upp::ArrayCtrl::Column::Edit(Upp::Ctrl*&)'


I'll try to fix this problem Smile

[Updated on: Fri, 25 October 2019 09:31]

Report message to a moderator

Re: How to create a Ctrl on selection? [message #52596 is a reply to message #52593] Fri, 25 October 2019 09:49 Go to previous messageGo to next message
mirek is currently offline  mirek
Messages: 12105
Registered: November 2005
Ultimate Member
Use Array<EditDouble> nums, Array<EditInt> ints (or alternatevely just Array<Ctrl>) as members of EditorFileSequenziali and create widgets you need in these.

This example somewhat shows how to do it:

https://www.ultimatepp.org/reference$DynamicDlg$en-us.html

(although your overall context is different).

[Updated on: Fri, 25 October 2019 09:50]

Report message to a moderator

Re: How to create a Ctrl on selection? [message #52599 is a reply to message #52596] Fri, 25 October 2019 11:57 Go to previous message
SidusBrist is currently offline  SidusBrist
Messages: 4
Registered: October 2019
Junior Member
Thank you! Now it works!
Previous Topic: Button in Array segfault
Goto Forum:
  


Current Time: Tue Nov 19 07:09:20 CET 2019

Total time taken to generate the page: 0.02423 seconds