Subject RE: [IBO] Column ordering
Author Paul Vinkenoog
Hello Riho-Rene,

> Another thing. I want to show/hide some columns in runtime. Somehow
> i'm not succeeding in it
> Grid->GridLinks->SafeCommaText=Str; //here I set the column ordering
> (data is read into Str from INI file) //NB! There is a problem, when
> I hide some columns, then they are not saved into INI and I dont'
> have access to them anymore when I want to set them back to visible.

> for(i=0;i<Grid->GridFieldCount;i++)
> { if(Grid->GridFields[i]->FieldName=="REG"
> || Grid->GridFields[i]->FieldName=="CREF" )
> Grid->GridFields[i]->Visible=false;
> }
> This removes only first field, because the indexing changes as soon
> as I set one field unvisible...

You can prevent this by changing the last line in the loop to:

Grid->GridFields[i--]->Visible = false;

However, this would break if the optimizer replaced GridFieldCount
with a constant for the duration of the loop. I don't think it will,
but you never know... Also, it's better not to mess with the control
variable in a loop. So change the loop to:

for ( int i = Grid->GridFieldCount - 1; i; --i )
{ body stays same }

> ...and later I cant get back to this anymore. There must be some
> other, more normal way to do manipulate the grid (or dataset)

Indeed, once you remove fields from the Grid, you can't find them back
via the Grid. What I would probably do here (but maybe browsing the
help will give you better ideas!) is to create a StringList in your
program code for each Grid you want your users to be able to change.
There you can store the "default" ordering of all columns that *could
be* in the Grid. (If you can't use TIB_Query->FieldsIndex for this
purpose, e.g. because some columns must *always* remain hidden.)

Upon program exit (or upon every change) you'll still find the
"hidden" columns there.

But you could also create a struct type that holds
a) a column name
b) a bool "Visible"
c) and maybe more: width..., ...

...and use a vector or list of these structs in your app. When the
Grid order changes, change the order in the vector or list (or use a
field in the struct to indicate the ordering).


Do things more or less like you do them now, but have a StringList to
store the names of columns that got hidden during the execution of the
app. Later (for instance when closing) you can retrieve the column
names from that StringList.

Paul Vinkenoog