Managing columns via code

Hello,

to manage columns, there are some macro (PHP) sc_field_display({My_Field}, on/off), to show or not a field, there is also the button Columns, and there user can choose which columns see, which not, and in which order they are shown in the grid.

Is there a way to select the order of column to show, via code ?

After I made a grid with field1, field2 and field3, sometimens I want to see field1, field2 and field3, sometimes field1, field2 (and field3 hidden), but sometimes I need to show field3, field1 and field2, how can I do that ?