From 3493e788131516714506363c8d88156ec2243d46 Mon Sep 17 00:00:00 2001 From: Kenny Shields Date: Tue, 16 Sep 2014 23:24:24 -0400 Subject: [PATCH] Add columnlist:SizeColumnToData --- objects/columnlist.lua | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/objects/columnlist.lua b/objects/columnlist.lua index 614b022..ee168e6 100644 --- a/objects/columnlist.lua +++ b/objects/columnlist.lua @@ -933,4 +933,31 @@ function newobject:GetColumnResizeEnabled() return self.canresizecolumns +end + +--[[--------------------------------------------------------- + - func: SizeColumnToData(columnid) + - desc: sizes a column to the width of its largest data + string +--]]--------------------------------------------------------- +function newobject:SizeColumnToData(columnid) + + local column = self.children[columnid] + local list = self.internals[1] + local largest = 0 + + for k, v in ipairs(list.children) do + local width = v:GetFont():getWidth(self:GetCellText(k, columnid)) + if width > largest then + largest = width + v.textx + end + end + + if largest <= 0 then + largest = 10 + end + + self:SetColumnWidth(columnid, largest) + return self + end \ No newline at end of file