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 » Change row appearance based on column value in that row
Change row appearance based on column value in that row [message #46634] Fri, 17 June 2016 11:08 Go to next message
slashupp is currently offline  slashupp
Messages: 193
Registered: July 2009
Experienced Member
I have looked at http://www.ultimatepp.org/forums/index.php?t=msg&goto=34 851& but is of no help at all.

I want to change the appearance of a given row (font/style/color) using a Display based on the values
of one or more of the columns in this row.

I know that I must use AddIndex but have no clue on how it works.

Currently I just tag clues to the ends of the values to be displayed and parse them out in the Display,
it works but is ugly code.

Can someone give me an example or point me to one where AddIndex is used?
Re: Change row appearance based on column value in that row [message #46768 is a reply to message #46634] Sun, 31 July 2016 14:02 Go to previous messageGo to next message
mirek is currently offline  mirek
Messages: 12098
Registered: November 2005
Ultimate Member
I guess the basic examples quite shows it:

http://www.ultimatepp.org/reference$ArrayCtrl$en-us.html

See how MyConvert is used.

The thing to know is that what goes to Convert and Display can be just loosly related to row cells. Basic AddColumn starts with "single Value", however you can Add more indicies to the column, in that case you will get ValueMap instead of single Value in Display.

So basically, you need to AddIndex (which does not add column), then for each AddColumn add this index. In Display you will get ValueMap of column value combined with this 'index'.

Mirek
Re: Change row appearance based on column value in that row [message #46815 is a reply to message #46768] Tue, 16 August 2016 12:26 Go to previous messageGo to next message
slashupp is currently offline  slashupp
Messages: 193
Registered: July 2009
Experienced Member

Quote:
I guess the basic examples quite shows it:


old-text:
Quote:
clear as mud, sorry
i cannot see the link these indexes has with the actual data or different columns
ID1 is used as a stand-alone 'array.AddIndex(ID1);' - where is the relevance? what does it index?
and again as 'array.AddColumn(ID2, ...).Add(ID1)...' - ID2 seems ok, but what is ID1 doing here?
ID3 just seemingly gets AddIndex()ed to the same column as a 'just because got it' - again relevance?, index to what?
do all three indexes here relate to the still-to-be-added-data in this column, whatever it is?
what data is added to the ValueMap?
looking at 'MyConvert()' doesn't help to clarify
looking at 'IdInfo' in 'ArrayCtrl' doesn't either


edit 16/8/23
okay, my attempt at understanding of what is happening:
- an un-attached (akin to a "variable") index is created with AddIndex()
- this index is then attached to some column with Add()
- the index added above will be associated with the value in that column when a row is added
- with a single index Display is called with just that value in that column - which makes no sense at all because it will be called with that value anyway, index or not
- with multiple indexes added to as many columns a ValueMap ([index]->value-in-associated-column)? is created - this seems to make sense - but display-routine magically has to know when its a single or a map? or do i have to in this case always create something like MyConvert?
- multiple indexes to same column - wtf? this throws me completely
array.AddColumn(ID2, "combined").Add(ID1).AddIndex(ID3).SetConvert(Single<MyConvert>());

ID1, ID2, ID3 ALL added to this single column - what am i missing?
in MyConvert you use 0, 1 and 2 as indexes into the ValueArray - what then is the purpose of the named indexes?





[Updated on: Tue, 23 August 2016 10:54]

Report message to a moderator

Re: Change row appearance based on column value in that row [message #46826 is a reply to message #46634] Tue, 23 August 2016 10:58 Go to previous messageGo to next message
slashupp is currently offline  slashupp
Messages: 193
Registered: July 2009
Experienced Member
can someone explain? - see my edited previous post
Re: Change row appearance based on column value in that row [message #46944 is a reply to message #46815] Sun, 25 September 2016 23:52 Go to previous messageGo to next message
mirek is currently offline  mirek
Messages: 12098
Registered: November 2005
Ultimate Member
slashupp wrote on Tue, 16 August 2016 12:26

- multiple indexes to same column - wtf? this throws me completely
array.AddColumn(ID2, "combined").Add(ID1).AddIndex(ID3).SetConvert(Single<MyConvert>());

ID1, ID2, ID3 ALL added to this single column - what am i missing?


Well, perhaps it is usefull to state that 'basic' operations are in fact

ArrayCtrl::AddIndex - adds 'index' (or 'column in datagrid')
ArrayCtrl::AddColumnAt - adds visual column which (at first) contains some index
ArrayCtrl::Column::Add - adds another index to the column - in this case, the value of column is ValueMap combining valus of all indices

now other methods are derived. For example

array.AddIndex(ID1);
array.AddColumn(ID2, "combined").Add(ID1).AddIndex(ID3);

can be written using basic ops as

array.AddIndex(ID1);
array.AddIndex(ID2);
array.AddIndex(ID3);
array.AddColumnAt(ID2, "combined").Add(ID1).Add(ID3);

Quote:

in MyConvert you use 0, 1 and 2 as indexes into the ValueArray - what then is the purpose of the named indexes?


Well, ArrayCtrl always creates ValueMap, but in U++, maps are ordered and ValueMap can be converted to ValueArray, that is why it is then possible to use just indexes. But you can convert to ValueMap instead and use IDs or in fact, you can use both IDs or indexes directly for Value (this was not quite possible at the time the example was written).

Hope this helps.

Mirek
Re: Change row appearance based on column value in that row [message #48729 is a reply to message #46944] Fri, 01 September 2017 11:20 Go to previous messageGo to next message
slashupp is currently offline  slashupp
Messages: 193
Registered: July 2009
Experienced Member
Revisiting this because I previously could not understand this AddIndex()-stuff.
(I used my work-around as described to achieve what I needed to)

I still cannot make any sense from this at all.

I now want to add a key to each row so that I can identify the specific entry when selected/clicked
with the real data in another container using this key.

I can find no way to add/associate a row-level key !?!?
no straightforward, intuitive way

any advice?
Re: Change row appearance based on column value in that row [message #48730 is a reply to message #48729] Fri, 01 September 2017 13:34 Go to previous messageGo to next message
mirek is currently offline  mirek
Messages: 12098
Registered: November 2005
Ultimate Member
What about AddKey ? Which is essentially the same as AddIndex, just checks that it is added as the zero index.

ArrayCtrl list;
list.AddKey(); // not visible
list.AddColumn("Something");

list.Add(1, "One");
list.Add(2, "Two");

list.GoBegin();
ASSERT(list.Get(list.GetCursor(), 0) == 1);
ASSERT(list.GetKey() == 1);
Re: Change row appearance based on column value in that row [message #48731 is a reply to message #48730] Fri, 01 September 2017 15:26 Go to previous messageGo to next message
slashupp is currently offline  slashupp
Messages: 193
Registered: July 2009
Experienced Member
That works well, thx mirek.

---
Can I assume that AddKey() and AddIndex() effectively adds hidden columns
that I then can access through column-order-index?
e.g.:
    ar.AddIndex(); ar.AddColumn(); ar.AddIndex();

and I can access these with:
    int idx=ar.GetCursor();
    if (idx>=0)
    {
        int first_index=ar.Get(idx, 0);
        int first_data=ar.Get(idx, 1);
        int second_index=ar.Get(idx, 2);
        ...
    }

Re: Change row appearance based on column value in that row [message #48732 is a reply to message #48731] Sat, 02 September 2017 09:38 Go to previous message
mirek is currently offline  mirek
Messages: 12098
Registered: November 2005
Ultimate Member
You can say that.

More precise is to say that there are "data columns" ("Index") and "visible colums" and mapping between them. Visible column can have as its data source any number of other data columns.

AddIndex adds data column.

AddColumn adds data column and visible column and trivially maps data->visible.

Mirek
Previous Topic: Cursor row color/headers color in ArrayCtrl and SQLCtrl
Next Topic: How to hide/show gridctrl column at runtime
Goto Forum:
  


Current Time: Wed Nov 13 11:32:29 CET 2019

Total time taken to generate the page: 0.01656 seconds