In addition to what jeruku said, you aren't parenting the entries to the scroll child to begin with. You are also repeating a lot of code when it could be avoided:
Lua Code:
tab.ItemScrollFrame:SetClipsChildren(true)
local numButtons, lastButton = 0
for key, item in pairs(namespace.searchResult) do
local buttonName = key .. "Button"
local button = CreateFrame("Button", buttonName, tab.ItemScrollFrameChild, "OptionsListButtonTemplate")
button:SetSize(192, 10)
button:SetHighlightTexture("Interface\\BUTTONS\\UI-Listbox-Highlight2")
button:SetText(item.name)
if item.slot then
button.tooltipText = item.itemType .. ", " .. item.slot
else
button.tooltipText = item.itemType
end
button:SetScript("OnEnter", OnEnter)
button:SetScript("OnLeave", OnLeave)
button:SetScript("OnClick", OnClickItemFrameButton)
if lastButton then
button:SetPoint("TOPLEFT", lastButton, "BOTTOMLEFT", 0, -1)
else
button:SetPoint("TOPLEFT", 4, -4)
end
numButtons, lastButton = numButtons + 1, button
tab[buttonName] = button
end
if lastButton then
local width, height = lastButton:GetSize()
tab.ItemScrollFrameChild:SetSize(width, numButtons * (height + 1) - 1)
end
I'm unsure what you are trying to accomplish with the "tab.buttonName" stuff unless you meant "tab[buttonName]" so that's what I changed it to, remove it if you aren't actually using it elsewhere.