LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Automatically adjust width of colums on Table

If I populate a table from a database, I would like to automatically adjust the width of the respective columns based on the maximum width of the text contained in the respective columns. I see that there is a property to automatically adjust row height but I can't find a way to automatically adjust the width. Since this is based on selected font, how would I determine the pixel width of a string such that I can use the property node of cell width to achieve my objective?
0 Kudos
Message 1 of 5
(2,822 Views)
The trick is to use the "get text rect" vi (in the graphic & sound > Picture functions) sub-palette.
However, I think I missed something since to get it work properly, I'm obliged to concatenate a space to the cell string.
The remaining problem (until NI add the function) is that you have to define manually which font is used.
See the attached example.

CC
Chilly Charly    (aka CC)

         E-List Master - Kudos glutton - Press the yellow button on the left...
        
Message 2 of 5
(2,804 Views)
Charly is right. The way to do this is to use the GetTextRect.vi. You will probably want to use a loop to examine the length of each cell's text and set the cell width to the longest length, perhaps padded a bit. You may want to check out this post as well:
http://forums.ni.com/ni/board/message?board.id=170&message.id=65837&requireLogin=False

Let us know if this doesn't help!

Megan B.
National Instruments
0 Kudos
Message 3 of 5
(2,785 Views)
Sorry, I forgot the attachment !

CC
Chilly Charly    (aka CC)

         E-List Master - Kudos glutton - Press the yellow button on the left...
        
Message 4 of 5
(2,780 Views)
Charly and Megan....Thanks for your help.

The attached VI clearly illustrates the discussion.
0 Kudos
Message 5 of 5
(2,755 Views)