Choose Language Hide Translation Bar
Level I

Resizing a Data Grid Box to exclude blank rows and columns


I'm trying to find a way to take a snapshot of just the populated cells of a data table (i.e. without any side panels, blank rows at the bottom or blank columns to the right).

I've recently discovered the Data Grid Box display box, which almost enables me to do what I want - but I need a way to size it so that the populated grid of cells completely fills it. I can do this manually by trial and error, but I'd like to do it automatically.


Is this possible? I enclose below a sample script which illustrates what I'm trying to do.


Many thanks


// Start of program;

Names Default To Here( 1 );


dt = Open( "$SAMPLE_DATA/" );

dt << close side panel; // I only want to see the data grid;


// First I'll color some cells to illustrate something;


// Any yield less than 9 will be painted red;
CellsToPaint = dt << get rows where(as column(:yield) < 9);
:yield << color cells(RGB Color(1, 0, 0), CellsToPaint);


// Any yield more than 15 will be painted green;
CellsToPaint = dt << get rows where(as column(:yield) > 15);
:yield << color cells(RGB Color(0, 1, 0), CellsToPaint);


// Put it into a Data Grid Box so I can copy it as a picture;
dgb = Data Grid Box( ); dgb << Set Data Table(dt);


// If I don't resize it there will be extra blank rows and columns visible;
// I can shrink it manually - but I want to automate this bit if I can;

dgb << set width(325);
dgb << set height(340);


// Let's see what I've got now;

new window("My Data Grid Box", dgb);

Path = "$DESKTOP/snapshot.png";

dgb << save picture(Path, "png");


// Re-open it inside a picture box;

pb = picture box(open(Path, png));


// And display the final image;

new window("My Snapshot", panelbox("My Snapshot", pb));


// End of program;


Re: Resizing a Data Grid Box to exclude blank rows and columns

Given the way you describerd what's needed, you could also try:


Names Default To Here( 1 );
dt = Open( "$SAMPLE_DATA/" );
tb = TableBox();
for(c=1, c<=NCol(dt), c++,
	thisCol = Column(dt, c);
	if ((thisCol << getDataType) == "Numeric",
		// Numeric column
		tb << Append(NumberColBox(thisCol << getName, thisCol << getValues)),
		// Assumed Character column
		tb << Append(StringColBox(thisCol << getName, thisCol << getValues))
Close(dt, NoSave);
tb << savePicture("$DESKTOP/snapshot.png", "png");
Level I

Re: Resizing a Data Grid Box to exclude blank rows and columns

Hi Ian - yes, it's true I could do it that way; however the underlying motivation for asking the question was that I wanted to retain the cell colouring that I'd built into the original data table.  I don't think I can colour the cells individually in a Table Box in the same way that I can colour the cells in a data table, is that right?


Something else that's confusing me is that when I originally assembled the example at the top of this thread, the side panels of the data table were always supposed to be hidden before I took the screen shot (hence the "dt <<  close side panel" line).  However I've just spotted I made an error there: that line ought to be "dt << close side panels(1)".  This seems to work properly, but when the data table is subsequently copied into the Data Grid Box, the side panel sometimes (but not always) reappears.  I see the Data Grid Box also has a "< close side panels" property, but I can't find a combination of these two properties that consistently removes the side panel from the Data Grid Box.  Am I using the "<< close side panels" property correctly?


Many thanks,



Re: Resizing a Data Grid Box to exclude blank rows and columns

Yes, I though those references to colours were there for a reason :) . . .


Although 'NumberColBox()' and StringColBox()' understand '<<textColor()' and '<<backgroundColor()' these operate on the whole column as perhaps one might expect.


Regarding manipulating the side panels, please do use if you see unexpected behaviour.


Article Labels

    There are no labels assigned to this post.