I am using M 8.0.4.
I am use TableView in demo Manipulate[] to display final solution data, which is a matrix of numerical data.
TableView is very nice to use, since it comes with an automatic scroll bars to move down the rows and to the right over the columns, so that one can see the whole matrix, while keeping the overall display area fixed. (I have an image at the bottom)
The problem that I am not able to find a solution for, is that I need to format the matrix data, so that it looks nice. Otherwise, if the a data element is too large to fit in a cell, it will wrap around, making the TableView misaligned. I also need to adjust decimal point an such other formatting.
I can’t apply NumberForm nor AccountForm to the data, and then apply TableView on the result, because TableView does not like to see those wrappers, it needs the numbers.
But if apply the AccountingForm to the TableView, then the numbers that represent the row numbers and column numbers, which are added by TableView automatically, get formatted as well. And I do not want those formatted as well. A row number should remain an integer, not floating point. I just want the data itself formatted.
I could not figure how to format the data from inside Table view. When I use FullForm to see how the data is kept inside TableView, I could not figure how to format it without breaking TableView.
I’ll show the problem, then show what I tried.
(* make up some data, and make a TableView of it *)
data = {{-1234.8, 0.123}, {0.12345678, 0.1234}}
tbl = TableView[data, ItemSize -> {{3, {8}}}, DefaultBaseStyle -> 11,
Spacings -> {.2, .1}, FrameStyle -> Gray]

Notice the row numbers and columns number (marked) are positive integers.
Now, I wanted to format the data itself, (the exact formatting options used below is just an example)
AccountingForm[tbl, {6, 3}, NumberSigns -> {"-", "+"},
NumberPadding -> {"", ""}, SignPadding -> True]
But now the Table rows and columns are also formatted:

The FullForm of TableView is:
In[156]:= FullForm[tbl]
TableView[List[List[-1234.8`,0.123`],List[0.12345678`,0.1234`]],
Rule[ItemSize,List[List[3,List[8]]]],
Rule[DefaultBaseStyle,11],Rule[Spacings,List[0.2`,0.1`]],
Rule[FrameStyle,GrayLevel[0.5`]]]
So the data in TableView can be pulled out using
In[166]:= tbl[[1]]
Out[166]= {{-1234.8,0.123},{0.12345678,0.1234}}
But when I change tbl[[1]], using ReplacePart[], with an AccountingForm version of the data, TableView no longer works:
formattedData =
AccountingForm[data, {6, 3}, NumberSigns -> {"-", "+"},
NumberPadding -> {"", "0"}, SignPadding -> True];
In[245]:= tbl=ReplacePart[tbl,1->formatted]
Out[245]= TableView[{{-1234.8,+0.123},{+0.123,+0.123}},
ItemSize->{{3,{8}}},DefaultBaseStyle->11,Spacings->{0.2,0.1},
FrameStyle->GrayLevel[0.5]]
So, I broke TableView. Since it does not display any more.
Question is: How to format numeric data that goes into TableView without affecting the row/column index values?
Fyi, this is how the TableView looks inside one Manipulate demo I have. Notice the automatics scroll-bars. (In this one, I am not using NumberForm and its friends to do the formatting. But what I did is not very efficient, I’d rather use NumberForm if I can, hence my question)

thanks
update 12/22/11 1:30 AM
Here is a complete code example for Mike to follow up on his answer below
data = {{-1234.8, 0.123}, {0.12345678, 0.1234}};
newData =
Map[AccountingForm[#, {6, 3}, NumberSigns -> {"-", "+"},
NumberPadding -> {"", ""}, SignPadding -> True] &, data, {2}];
tbl = TableView[newData, ItemSize -> {{3, {8}}}, Spacings -> {.2, .1},
FrameStyle -> Gray]
Now how exactly do I use the Cell command for the above? (This is in Manipulate, not a notebook session, Manipulate runs all in one cell. I can’t make separate cells and such in this code. But for trying it, I can in a new notebook, but the actual code that will use this solution, has to run in a Manipulate with no Cells.
Update 12/22/11 5 am
I am noticing some not good performance of TableView. Consider this code
Remove["Global`*"];
ClearSystemCache[]
m1 = MemoryInUse[$FrontEnd];
N[m1/10^6]
n = 256;
data = Table[RandomReal[], {n}, {n}];
TableView[data, ContentSize -> {300, 300}]
m2 = MemoryInUse[$FrontEnd] - m1;
N[m2/10^6]
The data itself, assuming double for the reals, is about half MB only. ByteCount says
2 MB due to other bookkeeping data struct.
In[114]:= ByteCount[data]/10^6//N
Out[114]= 2.10948
But Front end seems to use much more RAM (for the whole TableView I mean not just the data), sometimes I get 20 MB and sometimes much more (got 100 MB at one time). But if you try the above on your computer, you’ll notice M is having hard time with this. I think it might be the rendering of the table part that causes M to take so much time.
I do not think 256 by 256 is such a large matrix. Even with 128 by 128, it was having hard time to render it on the screen. Once it is up, then it is fast and no problem using it.
It looks like TableView is not yet optimized well. I think I will only use it to display small part of the solution Matrix as the performance is not good to use it in a demo to display the whole solution, it will make the demo look bad.
The problem is that my solution matrix can be large, and I wanted a away to display the data in limited amount of GUI space. TableView is all what I can find that comes with scrollbars build-in. Nothing else in the Manipulate controls has something like this to use, so I have to use TableView.
Update 12/22/11 4 PM
Thanks for the hint by Mike below, I am now looking at using Pane with Scollbars, and it is working better than TableView. (still little slow with large data, but not as bad as TableView)
Here is a code example of doing that:
n = 32;
data = Table[RandomReal[], {n}, {n}];
grid = Grid[data, Spacings -> {.4, .4}, Alignment -> Left, Frame -> All];
grid = Style[NumberForm[grid, {6, 5}], LineBreakWithin -> False];
pane = Pane[grid, ImageSize -> {200}, Scrollbars -> True]

Only problem I noticed so far is that when n gets large, Pane generates this outer frame saying very large output was generated. But I am sure there is a programmatic way (option somewhere) to turn that effect off, I just started looking at this and should be able to find a way around this once I have my coffee. (fingers crossed)

good news
The “Very large output was generated” ONLY showed up when in notebook interface. When I put the code in a Manipulate and and run it, it did not show this output frame. So, I am happy now and this issue is closed. I’ll use Pane from now on. (Thanks again to Mike)
btw, to remove the message in question, here is a useful link I found:
http://forums.wolfram.com/mathgroup/archive/2009/Apr/msg00935.html
but I did not need to do anything for what I am doing.
I guess this is a different enough method to post as another answer, though it clearly borrows from Mike’s answer.
Since using
ToStringwas non-intuitive, I decided to explore it a bit more. It seems thatTableViewsuppresses quotation marks in strings, but only bare strings. e.g.:Other interesting behavior can be seen with 2D formatted strings: