LabWindows/CVI

cancel
Showing results for 
Search instead for 
Did you mean: 

Auto Sizing Table Cells Height and Width

I want to auto size table cells (both the height and width) based on the text strings they display.  Some of the text strings have multiple lines.  I have tried setting the ATTR_SIZE_MODE to the SIZE_TO_CELL parameters but it did not achieve the desired results.  Basically I would like the cells to be sized as if the user double-clicked the row and column separators.  I have used the GetTextDisplaySize function in the past but I was hoping I’m just missing something simple.

0 Kudos
Message 1 of 14
(5,748 Views)

Hello John,

There is a function SetColumnWidthToWidestCellContents to adjust the column width automatically. It's actually in the "Trees" library, but if works for tables too. Unfortunately there is no SetRowHeightToHighestCellContents or some function like that Smiley Sad

 

Message 2 of 14
(5,732 Views)

...

Message Edited by Wim S on 04-25-2007 09:17 AM

0 Kudos
Message 3 of 14
(5,741 Views)

Thanks that does the trick for the width.  I never thought to look in the tree control functions.  The CVI help does not list that function as one of “Table Control Functions” but in the detailed function description it does refer to a table column.

 

It would be nice if they had a similar function for the row height.

 

Thanks again for your help.

 

John

 
0 Kudos
Message 4 of 14
(5,723 Views)
Hi John,

For the row height, this may not be exactly what you want, but there is a cell attribute you can use that might help. If you know ahead of time how many lines of text you will be using on a given cell, you can "register" that information with each cell, via the use of the ATTR_MIN_NUM_LINES_VISIBLE attribute. So, in your example, you can do the following:

    SetTableCellAttribute (panelHandle, PANEL_TABLE, MakePoint (1, 1), ATTR_MIN_NUM_LINES_VISIBLE, 3);

Then, when you use VAL_SIZE_TO_CELL_IMAGE_AND_FONT and VAL_SIZE_TO_CELL_FONT as the row's size mode, it will take this information into account.

By the way, you raise a good point about the SetColumnWidthToWidestCellContents being missing from the list of table control functions. That was an oversight that should be corrected. Sorry about that.

Luis
0 Kudos
Message 5 of 14
(5,708 Views)

Luis:

Thanks that also helps. 

John

0 Kudos
Message 6 of 14
(5,701 Views)
Okay, while the original poster seems to be satisfied I'm still stuck with the problem. I have arbitrary text in a table cell that is set to word wrap. I now want the table cell to be only as high as needed (fixed width). Sounds simple enough, but seems to be all but impossible in CVI. There doesn't seem to be any way to auto-size the cell or even to determine the needed height, short of re-doing the word wrap calculations myself. Which is something I don't really like to spend my time on. Any more ideas?
0 Kudos
Message 7 of 14
(5,449 Views)
Hello Marcel,
 
Yeah... I don't blame you. It's not an obvious thing, by any means. NI will be adding a function in a future release of CVI that will also handle table rows. In the meanwhile, this is what you can do:
 
1. Create a temporary textbox control and set its width to match the fixed column width, plus 6 pixels (to take into account the frame of the textbox).
2. Set the wrap mode of the textbox to be word wrap.
3. Set the value of the textbox contents to match the table cell contents, using SetCtrlVal.
4. Get the resulting number of lines in the textbox, using GetNumTextBoxLines
5. Pass the number of lines to the ATTR_MIN_NUM_LINES_VISIBLE attribute that I referred to earlier.
 
Of course this will only handle one cell in your row. If you have multiple cells in each row, then you'd have to do this for each cell.
 
Luis
0 Kudos
Message 8 of 14
(5,442 Views)
Hello Luis.

Many thanks for your answer. Still this is one thing that really bugs me about CVI, sometimes it takes some almost comically absurd effort to do the simplest of things.

Oh well, at least it works, though very inefficiently so. In some cases I cannot use it as it slows things down too much. But in any case, I attached a simple utility function for anybody to use.

Cheers, Marcel
Message 9 of 14
(5,414 Views)

Hi Marcel,

thanks a lot for posting the code. It's always nice if some code can be reused by other people Smiley Happy

0 Kudos
Message 10 of 14
(5,411 Views)