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 with enabled/Disabled columns
ArrayCtrl with enabled/Disabled columns [message #3042] Fri, 05 May 2006 07:09 Go to next message
lundman is currently offline  lundman
Messages: 175
Registered: March 2006
Location: Tokyo
Experienced Member
I have an ArrayCtrl with 7 elements, like that of the output of
"ls":

index, name, user, group, size, date, perm

The first is an Index, and is not viewed. Next I thought it would be nice if the user could chose which fields are used. To avoid having to store which column is what in my code, I went down the route where I always add 7 elements, but turned them off or on depending on user selected options.

However, I could see no apparent way to just enable or disable a column. (is that the case? HeaderObject().HideTab(int) did nothing for me).

So, instead I went down the road where I either AddColumn(), or AddIndex() based on whether or not it is enabled.

This appears to work ok, except when I call .Reset() and re-add the Columns/Indeces. I lose the User set Width.

It would appear that I have a ColumnsWidths(char *) function to set them, but I am unsure how to get what they are. HeaderObject().GetTabWidth() seems to give me the default/initial width, not the current width.

On the other hand, Serialize() appears to work fine, but it works with streams. But perhaps that is the proper path? (Do I really need to open a stream just to save the widths?)

Re: ArrayCtrl with enabled/Disabled columns [message #3046 is a reply to message #3042] Fri, 05 May 2006 08:56 Go to previous messageGo to next message
mirek is currently offline  mirek
Messages: 13975
Registered: November 2005
Ultimate Member
lundman wrote on Fri, 05 May 2006 01:09

I have an ArrayCtrl with 7 elements, like that of the output of
"ls":

index, name, user, group, size, date, perm

The first is an Index, and is not viewed. Next I thought it would be nice if the user could chose which fields are used. To avoid having to store which column is what in my code, I went down the route where I always add 7 elements, but turned them off or on depending on user selected options.

However, I could see no apparent way to just enable or disable a column. (is that the case? HeaderObject().HideTab(int) did nothing for me).

So, instead I went down the road where I either AddColumn(), or AddIndex() based on whether or not it is enabled.

This appears to work ok, except when I call .Reset() and re-add the Columns/Indeces. I lose the User set Width.

It would appear that I have a ColumnsWidths(char *) function to set them, but I am unsure how to get what they are. HeaderObject().GetTabWidth() seems to give me the default/initial width, not the current width.

On the other hand, Serialize() appears to work fine, but it works with streams. But perhaps that is the proper path? (Do I really need to open a stream just to save the widths?)





Well, first of (but I guess you have already realized that), there is one important thing about ArrayCtrl and columns - mapping "indexes" (well, cells in line, "logical" columns) to table columns does not need to be 1:1. Some indexes do not need to be mapped at all, some columns do not have to be mapped to index (but rather be fed with line index), some columns can be mapped to more than single index. To make it more fun, some indexes (or group of indexes or line index) can even be mapped to other widgets in the window (well, this U++, so not necessarily in the same window...).

Now, HeaderObject().HideTab SHOULD work. At least, this works:

#include <CtrlLib/CtrlLib.h>

void HideTab(ArrayCtrl *x)
{
	x->HeaderObject().HideTab(1);
}

GUI_APP_MAIN
{
	ArrayCtrl a;
	a.AddColumn("Column");
	a.AddColumn("Click to hide").HeaderTab().WhenAction = callback1(HideTab, &a);
	for(int i = 0; i < 100; i++)
		a.Add(i, i);
	TopWindow app;
	app << a.SizePos();
	app.Run();
}


ColumnWidths is a special function to work together with "Ctrl-Click" trick. As it is quite annoying to guess initial values for ArrayCtrl header, when you are in debug mode, you can setup widths as you want them, then Ctrl-Click the header with mouse and special, debug-version only, code inside HeaderCtrl will put ColumnWidths call code to clipboard that you can then insert into your C++ code to get the same widths. Maybe a little bit hacky, but effective...

However, as this operation itself and Serialize too use GetTabWidth (and work Wink, there is most likely other problem in your code...

Mirek
Re: ArrayCtrl with enabled/Disabled columns [message #3047 is a reply to message #3042] Fri, 05 May 2006 09:02 Go to previous messageGo to next message
fudadmin is currently offline  fudadmin
Messages: 1321
Registered: November 2005
Location: Kaunas, Lithuania
Ultimate Contributor
Administrator
Maybe this is helpful:
(You can store column widths in a string)
	arr.AddColumn("first",1);
	arr.AddColumn("second",2);
	arr.AddColumn("third",3);
	String arrColumnWidths;
	for (int i=0; i<arr.GetColumnCount();i++){
		arrColumnWidths << AsString(arr.HeaderObject().GetTabWidth(i))+" ";
	}
	arr.ColumnWidths(arrColumnWidths); //set widths from string "1 2 3"
	PromptOK(arrColumnWidths);  //have in mind now they are in pixels...

Re: ArrayCtrl with enabled/Disabled columns [message #3050 is a reply to message #3046] Fri, 05 May 2006 09:33 Go to previous messageGo to next message
lundman is currently offline  lundman
Messages: 175
Registered: March 2006
Location: Tokyo
Experienced Member

Thanks for the reply.

Just compiled your program to see if it would behave the way I observed (couple of columns after the end to hide, results in an empty column in my code)...

.. but of course it works just fine. This does seem to be a better way to do the code, since then I do not need to care/mess with the Widths, nor re-create the ArrayCtrl when user changes the settings.

Your replies are always fast and helpful, thanks.

fudadmin: I did that code, but it would always return "1 2 3" as in your example, not whatever values that tabs would be if made bigger/smaller by using mouse. But again, could be something I do in my code.

Re: ArrayCtrl with enabled/Disabled columns [message #3051 is a reply to message #3050] Fri, 05 May 2006 09:56 Go to previous message
lundman is currently offline  lundman
Messages: 175
Registered: March 2006
Location: Tokyo
Experienced Member

Naturally it just works. Sigh Smile In my defense, sourceforge was down most of my morning, so no easy access, and Auto Assist cores too much in my NetBSD port so I turn it off Smile


Some caveats that got me were that HideTab() index refers to the visible tabs, ie, without whatever AddIndex() I also have. As it should of course, just didn't occur to me immediately.


Secondary, there seems to be a bug with horizontal scrollbar. It turns on before my tabs are even close to the right-side edge. Almost like it is adding up all tabs, including those Hidden, to work out when to enable the horizontal scrollbar.

I can live with that for now.

That takes care of that TODO. Only the "let users chose the order of name,size,date,user,group,perms" in ArrayCtrl, but that feels like a lot of work Smile

Cheers
Previous Topic: ArrayCtrl grid color
Next Topic: ArrayCtrl cell consisting of edit and helper button
Goto Forum:
  


Current Time: Mon Apr 29 13:13:58 CEST 2024

Total time taken to generate the page: 0.03389 seconds