How do I get the last item in the row when using UIGridLayout?

I want to get the last item so I can use that for navigation purpose, if your confuse, here is the picture
Untitled

for example, the Max cell is 3*3, and I want to get the circle that is X

Here is some code I just whipped up that prints the last Frame in each row:

UIGridLayout = script.Parent.Frame.UIGridLayout
LastCollumnItems = {}
for x = 1,(#UIGridLayout.Parent:GetChildren() - 1)/UIGridLayout.FillDirectionMaxCells,1 do
    table.insert(LastCollumnItems,UIGridLayout.Parent:GetChildren()[(x * UIGridLayout.FillDirectionMaxCells) + 1]) -- the 1 that is added is to account for the UIGridLayout itself
end
for num, item in pairs(LastItems) do
	print(item)
end

This only is accurate, of course, if the only objects you have as a child to your parent object, are the frames and the UIGridLayout.
image
If you add any other objects inside your parent frame, you will have to change the 1s in the example code, to the number of extra object you have.

Hope this helps!

1 Like