U++ framework
Do not panic. Ask here before giving up.

Home » U++ Library support » ArrayCtrl, HeaderCtrl & GridCtrl » Ctrls<>() Callback / Disable some rows
Ctrls<>() Callback / Disable some rows [message #9991] Tue, 12 June 2007 22:31 Go to next message
kcabobert is currently offline  kcabobert
Messages: 51
Registered: January 2007
Location: USA
Member
I have two issues... but don't want two threads (I'm lazy...).

First, let me setup the problem:

1) I have an ArrayCtrl which I populate dynamically (I read the values from a database based on search criteria entered elsewhere).

2) My ArrayCtrl has an Index column (via AddIndex("primary_key","id")), a column of options (via AddColumn("use","Use").Ctrls<Option>()), and a name column (via AddColumn("name","Name")).

3.a) I need to SOMETIMES assign a callback to the option column that will uncheck all other options (like a radio ctrl), other times multiple selections are OK. I can do this if I can reliably figure out in which row the option that triggered the callback resides (I need people to be able to select via mouse or keyboard).

3.b) In some cases I may want one option completely disabled (in other words one row disabled). However, I still need the row to list. In these cases removing the option ctrl is acceptable.

I have found two threads which appear to have similar needs / problems:
http://www.ultimatepp.org/forum/index.php?t=msg&th=602
http://www.ultimatepp.org/forum/index.php?t=msg&th=605

I am not so clear on what exactly the GridCtrl does... but I gather that it may allow me to accomplish this? As a note, I think I would prefer to leave this as an ArrayCtrl.

I have used the WhenCtrlsAction callback on the ArrayCtrl, but can not reliably decided which row tripped the callback.

Thanks for your help / thoughts,
Robert
Re: Ctrls<>() Callback / Disable some rows [message #9992 is a reply to message #9991] Tue, 12 June 2007 23:02 Go to previous messageGo to next message
unodgs is currently offline  unodgs
Messages: 1367
Registered: November 2005
Location: Poland
Ultimate Contributor

In GridCtrl when control does its action the cursor is always moved to the cell that owns it (this is one of the main difference to the ArrayCtrl). Knowing that you can easily determine control (cell) position in WhenUpdateCell using GetCursorPos() or GetCursor() if you're intrested only in row position.
Re: Ctrls<>() Callback / Disable some rows [message #9993 is a reply to message #9992] Tue, 12 June 2007 23:04 Go to previous messageGo to next message
kcabobert is currently offline  kcabobert
Messages: 51
Registered: January 2007
Location: USA
Member
Here is a general question: why ArrayCtrl and GridCtrl? Why not merge the two to simplify the library?

-- Added --

And here is my favorite part: where is the documentation on GridCtrl, and is it actually maintained? I see that it is segregated from the other controls... so I assume it is not maintained with the rest of the UPP code?

Is it possible to accomplish my needs using ArrayCtrl? I previously had the functioning by creating the Options using SetCtrl(..., new Option) then setting the details.

When I upgraded to the new upp version the Ctrls appears as gray boxes (in Windows, Linux, and Mac). My beta testers were less than pleased with the prospect of having to resize a column to check the box each time. I need to get an updated version of my software rolled out so I need to find a [quick] reliable solution.

Thoughts?

[Updated on: Tue, 12 June 2007 23:10]

Report message to a moderator

Re: Ctrls<>() Callback / Disable some rows [message #9994 is a reply to message #9993] Tue, 12 June 2007 23:36 Go to previous messageGo to next message
unodgs is currently offline  unodgs
Messages: 1367
Registered: November 2005
Location: Poland
Ultimate Contributor

kcabobert wrote on Tue, 12 June 2007 17:04

Here is a general question: why ArrayCtrl and GridCtrl? Why not merge the two to simplify the library?

They can't be merged (at least now). ArrayCtrl is the base array contol from the very begining and is used in many applications. I have created GridCtrl just to fit my needs (read about its features at my page).
Quote:


And here is my favorite part: where is the documentation on GridCtrl, and is it actually maintained? I see that it is segregated from the other controls... so I assume it is not maintained with the rest of the UPP code?


Documentation is the weakest point of GridCtrl. There is only unfinished tutorial (in GridCtrl package) and HomeBudget as an example. As for maintaining - you're wrong Smile It's actively developed. My time is very limited right now but I'll try to write better documentation soon.
Re: Ctrls<>() Callback / Disable some rows [message #9995 is a reply to message #9994] Wed, 13 June 2007 02:05 Go to previous messageGo to next message
kcabobert is currently offline  kcabobert
Messages: 51
Registered: January 2007
Location: USA
Member
I wasn't trying to demean the project... it sounds very good. I was simply concerned that it may have dwindled and be no longer developed.

Am I correct in assuming then that GridCtrl is my only option?

Robert
Re: Ctrls<>() Callback / Disable some rows [message #9996 is a reply to message #9995] Wed, 13 June 2007 04:57 Go to previous messageGo to next message
kcabobert is currently offline  kcabobert
Messages: 51
Registered: January 2007
Location: USA
Member
Is this correct? Why not add it to GridCtrl.h?

void Set(int r, Id c, const Value &val)
{
Set(r,aliases.Get(c),val);
}

The asm code doesn't compile right... but I assume that is on my end.

I get an error about line 918 ("inline Item& GetItem(int n, int m);"). It seems the function body is missing....

Aside from that it seems like it might work well.

Robert
Re: Ctrls<>() Callback / Disable some rows [message #9998 is a reply to message #9991] Wed, 13 June 2007 09:33 Go to previous messageGo to next message
mirek is currently offline  mirek
Messages: 14290
Registered: November 2005
Ultimate Member
kcabobert wrote on Tue, 12 June 2007 16:31


2) My ArrayCtrl has an Index column (via AddIndex("primary_key","id")), a column of options (via AddColumn("use","Use").Ctrls<Option>()), and a name column (via AddColumn("name","Name")).



Just a note: This was supposed to use those Id (or SqlId) things, like:

Id PRIMARY_KEY("PRIMARY_KEY"); // possibly global, "Id constant"
....
AddIndex(PRIMARY_KEY, "id");


Using char * there works as well, but it is a but more error prone (you can mistype the string) and U++ has to perform char * -> Id conversion. That is especially not very helpful if you are looping through the ArrayCtrl values.

3.a) I need to SOMETIMES assign a callback to the option column that will uncheck all other options (like a radio ctrl), other times multiple selections are OK.  I can do this if I can reliably figure out in which row the option that triggered the callback resides (I need people to be able to select via mouse or keyboard).

3.b) In some cases I may want one option completely disabled (in other words one row disabled).  However, I still need the row to list.  In these cases removing the option ctrl is acceptable.


Well, Ctrls part of ArrayCtrl seems to be really deficient.

I was thinking about the issue a lot and really the problem seems to be that we have stepped out of U++ paradigm here, introducing class factory, which is nice to solve simple problems, but fails with more complicated ones.

I plan to add some other interface for embeding widgets into ArrayCtrl that will rather use widgets that belong outside the ArrayCtrl (e.g. in the dialog). Something like:

struct MyDialog {
    Array<Option> option;

    void OptionColumn(Ptr<Ctrl>& ctrl, int index)
    {
        ctrl = &option.At(index);
    }

    MyDialog() {
        list.AddColumn("Options").Ctrls(THISBACK(OptionColumn));
    }
};


This way, you would have the full access to the list of options.

What do you think?

Mirek
Re: Ctrls<>() Callback / Disable some rows [message #9999 is a reply to message #9993] Wed, 13 June 2007 09:39 Go to previous messageGo to next message
mirek is currently offline  mirek
Messages: 14290
Registered: November 2005
Ultimate Member
kcabobert wrote on Tue, 12 June 2007 17:04

Here is a general question: why ArrayCtrl and GridCtrl? Why not merge the two to simplify the library?



I believe they are solving slightly different problem domains. E.g. ArrayCtrl is used even in DropList, it is just generic simple list designed to be used in various compositions, while GridCtrl has much richer interface, but sort of more specialized.

The reason it resides in separate package is more or less because it is too big to fit into CtrlLib. It is the same story as RichEdit...

Quote:


When I upgraded to the new upp version the Ctrls appears as gray boxes (in Windows, Linux, and Mac). My beta testers were less than pleased with the prospect of having to resize a column to check the box each time. I need to get an updated version of my software rolled out so I need to find a [quick] reliable solution.



Ops. Can you be more specific? What are grey boxes?
Re: Ctrls<>() Callback / Disable some rows [message #10000 is a reply to message #9999] Wed, 13 June 2007 10:37 Go to previous messageGo to next message
unodgs is currently offline  unodgs
Messages: 1367
Registered: November 2005
Location: Poland
Ultimate Contributor

Quote:

I wasn't trying to demean the project...

Why did you think I thought so? Wink I did not.
Quote:


Is this correct? Why not add it to GridCtrl.h?

void Set(int r, Id c, const Value &val)
{
Set(r,aliases.Get(c),val);
}


Ok, I will add it. But you can use now:
grid(COLUMN_ID) = val
or
grid.Set(COLUMN_ID, val);
to set value of cell in row pointed internally by rowidx. rowidx changes automaticaly if you add new row or change cursor position.
Quote:


The asm code doesn't compile right... but I assume that is on my end.
I get an error about line 918 ("inline Item& GetItem(int n, int m);"). It seems the function body is missing....


Please use latest dev package. All those problems should be corrected there.

[Updated on: Wed, 13 June 2007 10:38]

Report message to a moderator

Re: Ctrls<>() Callback / Disable some rows [message #10001 is a reply to message #9991] Wed, 13 June 2007 10:53 Go to previous messageGo to next message
mirek is currently offline  mirek
Messages: 14290
Registered: November 2005
Ultimate Member
OK, after more thinking, what about this simple (U++-ish Smile solution:

#include <CtrlLib/CtrlLib.h>

using namespace Upp;

struct App : TopWindow {
	Array<Option> option;
	ArrayCtrl a;
	
	void Do(int ii)
	{
		option[ii].SetFocus();
		for(int i = 0; i < option.GetCount(); i++)
			option[i].Enable(i == ii || option[ii]);
	}
	
	typedef App CLASSNAME;
	
	App() {
		a.AddColumn("Option");
		for(int i = 0; i < 300; i++) {
			a.Add(i & 4);
			a.SetCtrl(i, 0, option.Add().SetLabel("Test"));
			option.Top() <<= THISBACK1(Do, i);
		}
		a.SetLineCy(Draw::GetStdFontCy() + 8);
		Add(a.SizePos());
		Sizeable();
	}
};

GUI_APP_MAIN
{
	App().Run();
}

Re: Ctrls<>() Callback / Disable some rows [message #10017 is a reply to message #10001] Wed, 13 June 2007 23:36 Go to previous messageGo to next message
kcabobert is currently offline  kcabobert
Messages: 51
Registered: January 2007
Location: USA
Member
This is my response to several posts:

Quote:

OK, after more thinking, what about this simple (U++-ish) solution:


That is very similar to what I was previously doing... when I was getting the grey boxes. See the attached image.

I liked that method and everything was fine... expect the funky boxes.



Quote:

Ok, I will add it. But you can use now:
grid(COLUMN_ID) = val
or
grid.Set(COLUMN_ID, val);
to set value of cell in row pointed internally by rowidx. rowidx changes automaticaly if you add new row or change cursor position.


Well, that is fine, but it does not address my issue. I need to be able to set a cell's value that is in a different row than the cursor. I do not always know the column position... but I do know the column name. Hence the need for a Set( row, col_id, value ) method.

Is there another way to do this that I missed? If so please let me know.

Robert
Re: Ctrls<>() Callback / Disable some rows [message #10021 is a reply to message #10017] Thu, 14 June 2007 08:18 Go to previous messageGo to next message
unodgs is currently offline  unodgs
Messages: 1367
Registered: November 2005
Location: Poland
Ultimate Contributor

Quote:

Well, that is fine, but it does not address my issue. I need to be able to set a cell's value that is in a different row than the cursor. I do not always know the column position... but I do know the column name. Hence the need for a Set( row, col_id, value ) method.

Set(row, Id, value) is already in UVS.
Re: Ctrls<>() Callback / Disable some rows [message #10059 is a reply to message #9991] Mon, 18 June 2007 19:00 Go to previous messageGo to next message
kcabobert is currently offline  kcabobert
Messages: 51
Registered: January 2007
Location: USA
Member
Is there a SetCtrlValue methods in the new version as well?

rk
Re: Ctrls<>() Callback / Disable some rows [message #10061 is a reply to message #9991] Mon, 18 June 2007 19:44 Go to previous messageGo to next message
kcabobert is currently offline  kcabobert
Messages: 51
Registered: January 2007
Location: USA
Member
My initial suggestion was wrong. It should rather be something like:

void Set(int r, Id c, const Value &val)
{
Set(r,aliases.Get(c)-fixed_cols,val);
}

Re: Ctrls<>() Callback / Disable some rows [message #10065 is a reply to message #9991] Mon, 18 June 2007 20:27 Go to previous messageGo to next message
kcabobert is currently offline  kcabobert
Messages: 51
Registered: January 2007
Location: USA
Member
I also think you have some inconsistent behavior with Get{...} and Set{...}. Some appear to auto-adjust for the Fixed{Column,Row} count and some do not.

For example, when using a index from 0 to GetCount to check the value of a particular column, and set the cell equal to zero if the cell value is one, I have to specify the FixedCount offset when getting values... but not when setting values.

Consider the below snippet:
	const int	offset	= gridctrl.GetFixedCount(),
			pos		= gridctrl.GetCursor();

	if ( atoi(gridctrl.Get("checked").ToString())==1 )
		for ( int t=0; t<gridctrl.GetCount(); t++ )
			if ( (t!=pos) && (atoi(gridctrl.Get(t+offset,"checked").ToString())==1)) {
				gridctrl.Set(t,"checked",0);
			}

[Updated on: Mon, 18 June 2007 20:28]

Report message to a moderator

Re: Ctrls<>() Callback / Disable some rows [message #10068 is a reply to message #10061] Mon, 18 June 2007 21:52 Go to previous messageGo to next message
unodgs is currently offline  unodgs
Messages: 1367
Registered: November 2005
Location: Poland
Ultimate Contributor

You're right as long as you use Set(), but inside GridCtrl I use Set0 which counts columns/rows with fixed ones, so aliases.Get(c) is perfectly fine in my case.
Re: Ctrls<>() Callback / Disable some rows [message #10069 is a reply to message #10065] Mon, 18 June 2007 21:57 Go to previous messageGo to next message
unodgs is currently offline  unodgs
Messages: 1367
Registered: November 2005
Location: Poland
Ultimate Contributor

Quote:

I also think you have some inconsistent behavior with Get{...} and Set{...}. Some appear to auto-adjust for the Fixed{Column,Row} count and some do not.

You're right. It looks like I missed this one:
Value GridCtrl::Get(int r, const char * alias)
{
	return Get0(r, aliases.Get(alias));
}

It's fixed now! Thanks.
Re: Ctrls<>() Callback / Disable some rows [message #10073 is a reply to message #10069] Mon, 18 June 2007 23:40 Go to previous messageGo to next message
kcabobert is currently offline  kcabobert
Messages: 51
Registered: January 2007
Location: USA
Member
Your code snippet it how it looks now... so I don't get it. Do I need to modify Get0?

Or, better yet, is there a newer (at least as stable) version I can download and use?

Robert
Re: Ctrls<>() Callback / Disable some rows [message #10074 is a reply to message #10073] Mon, 18 June 2007 23:50 Go to previous messageGo to next message
unodgs is currently offline  unodgs
Messages: 1367
Registered: November 2005
Location: Poland
Ultimate Contributor

I put here current implementation of GridCtrl::Get(row, Id) to show there is no r + fixed_rows as you suggested, but only r. I modified it and now it's in current uvs (internal versioning system of U++). I will release a new dev release and update SVN as only I get my main computer working. Sorry for shortcuts in my answers Smile
Re: Ctrls<>() Callback / Disable some rows [message #10075 is a reply to message #9991] Mon, 18 June 2007 23:54 Go to previous messageGo to next message
kcabobert is currently offline  kcabobert
Messages: 51
Registered: January 2007
Location: USA
Member
I think I have found another glitch... possibly in my code, but I don't think so.

I have two columns, one with checkboxes, one with names. Sometimes when I press the space bar is checks the PREVIOUSLY selected rows checkbox, not the currently selected row.

This behaviour is spuradic, and as I type this I can not reproduce it. Encountered this before?
Re: Ctrls<>() Callback / Disable some rows [message #10076 is a reply to message #10075] Tue, 19 June 2007 10:58 Go to previous messageGo to next message
unodgs is currently offline  unodgs
Messages: 1367
Registered: November 2005
Location: Poland
Ultimate Contributor

kcabobert wrote on Mon, 18 June 2007 17:54

I think I have found another glitch... possibly in my code, but I don't think so.

I have two columns, one with checkboxes, one with names. Sometimes when I press the space bar is checks the PREVIOUSLY selected rows checkbox, not the currently selected row.

This behaviour is spuradic, and as I type this I can not reproduce it. Encountered this before?

It seems like cursor pos is not changed in some rare situations. Could you post your test case? And what version of grid do you use?
Re: Ctrls<>() Callback / Disable some rows [message #10079 is a reply to message #9991] Tue, 19 June 2007 15:05 Go to previous messageGo to next message
kcabobert is currently offline  kcabobert
Messages: 51
Registered: January 2007
Location: USA
Member
I am using the version bundled with UPP-2007.1, I am not exactly sure what the version number is. Judging from the changelog I would say 2007.1rc3?

I will try to find a some simple test code / instructions to replicate as I finish updating my code to use GridCtrl.

As I recall it is when selections are made using a combination of the mouse (to enter GridCtrl), then using <enter> and <space> to make selections. As I said, I do not recall the specific sequence.


Now that a few little bugs have been ironed out it seems like GridCtrl will accomplish what I need. Nice work!!

Robert
Re: Ctrls<>() Callback / Disable some rows [message #10080 is a reply to message #9991] Tue, 19 June 2007 15:24 Go to previous messageGo to next message
kcabobert is currently offline  kcabobert
Messages: 51
Registered: January 2007
Location: USA
Member
Except one (hopefully easy) thing: how can I disable one row? Or, at the minimum, one cell which I just inserted?

Verbal example: I have a gridctrl with a column of check boxes and a column of names, when I populate (as I Add(sql result vector)) the grid I need to disable some checkboxes. I tried calling NoEditable and NoClickable with no luck.


Is there an easy way to achieve this?

Thanks,
Robert
Re: Ctrls<>() Callback / Disable some rows [message #10081 is a reply to message #10080] Tue, 19 June 2007 15:56 Go to previous messageGo to next message
unodgs is currently offline  unodgs
Messages: 1367
Registered: November 2005
Location: Poland
Ultimate Contributor

Quote:

Verbal example: I have a gridctrl with a column of check boxes and a column of names, when I populate (as I Add(sql result vector)) the grid I need to disable some checkboxes. I tried calling NoEditable and NoClickable with no luck.

Generally NoEditable should prevent creating embeded control. However it works well before the window with grid is displayed. Later GridCtrl::Add(..) call SyncCtrls() (method responisble for creating/updating embeded controls) immediately after creating row. You have to call Add() before NoEditable() which does not update controls' positions and you still see them able to be edited. So as a workaround make SyncCtrls() in GridCtrl class public and call it after adding rows and making some of them uneditable. I'll try to find correct solution to this problem before new dev release (Add()/AddRow() call SyncCtrls and I would like to avoid clling it a second time in NoEditable() somehow).
Re: Ctrls<>() Callback / Disable some rows [message #10082 is a reply to message #10079] Tue, 19 June 2007 15:58 Go to previous messageGo to next message
unodgs is currently offline  unodgs
Messages: 1367
Registered: November 2005
Location: Poland
Ultimate Contributor

Quote:

I am using the version bundled with UPP-2007.1, I am not exactly sure what the version number is. Judging from the changelog I would say 2007.1rc3?

There were some important changes/bugs fixed after it. So I will make current snapshot of GridCtrl available on this forum today. Please check it.
Re: Ctrls<>() Callback / Disable some rows [message #10083 is a reply to message #9991] Tue, 19 June 2007 17:13 Go to previous messageGo to next message
kcabobert is currently offline  kcabobert
Messages: 51
Registered: January 2007
Location: USA
Member
I know calling SyncCtrls in NoEditable is less than ideal... but is something similar not the 'cleanest' solution?

What about creating some type of 'stripped' SyncCtrls that only affects the row being set to NoEditable?
Re: Ctrls<>() Callback / Disable some rows [message #10084 is a reply to message #9991] Tue, 19 June 2007 17:44 Go to previous messageGo to next message
kcabobert is currently offline  kcabobert
Messages: 51
Registered: January 2007
Location: USA
Member
This still does not quite look right. The Ctrl is not getting totally disabled (it still displays and is sometimes able to be checked). I think the SyncCtrls function needs a small tweak. I think if the row is set to NoEditable the Ctrl should be disabled. What are your thoughts on that?

[Updated on: Tue, 19 June 2007 17:45]

Report message to a moderator

Re: Ctrls<>() Callback / Disable some rows [message #10086 is a reply to message #10084] Tue, 19 June 2007 22:01 Go to previous messageGo to next message
mirek is currently offline  mirek
Messages: 14290
Registered: November 2005
Ultimate Member
kcabobert, this thread starts to be confusing, dealing with ArrayCtrl and GridCtrl without specification.

Please at least add "ArrayCtrl" or "GridCtrl" somewhere in your post Smile

Or start a new one...
Re: Ctrls<>() Callback / Disable some rows [message #10097 is a reply to message #9991] Wed, 20 June 2007 00:41 Go to previous message
kcabobert is currently offline  kcabobert
Messages: 51
Registered: January 2007
Location: USA
Member
Yeah, I thought about that... it sort of took a turn for the confusing.

Basically the thread focuses on GridCtrl after about the fourth post, with occasional references to ArrayCtrl after.
Previous Topic: GridCtrl align text in column
Next Topic: GridCtrl - Child Ctrl, selected row, focus issue
Goto Forum:
  


Current Time: Sat Apr 25 17:53:44 GMT+2 2026

Total time taken to generate the page: 0.01373 seconds