Jump to content

Add row on top of gridlist


JeViCo

Recommended Posts

Hello everyone! Could you help me with this? I tried to make it but it doesn't work properly (at all)

function moveToFirst(curpos)
	--local curpos = 5
	for r = 1,curpos do
		--print(r)
		if r == curpos then
			dgsGridListSetItemText(layergrid,1,1,"#1")
			dgsGridListSetItemText(layergrid,r,1,"#"..r)
		else
			local r1_data = dgsGridListGetItemData(layergrid,curpos-r,1) -- 4
			local r1_data2 = dgsGridListGetItemData(layergrid,curpos-r,2)
			--
			local r1_text = dgsGridListGetItemText(layergrid,curpos-r,2)
			local r1_text2 = dgsGridListGetItemText(layergrid,curpos-r,3)
			local r1_text3 = dgsGridListGetItemText(layergrid,curpos-r,4)
			--
			local r2_data = dgsGridListGetItemData(layergrid,curpos-r+1,1) -- 5
			local r2_data2 = dgsGridListGetItemData(layergrid,curpos-r+1,2)
			--
			local r2_text = dgsGridListGetItemText(layergrid,curpos-r+1,2)
			local r2_text2 = dgsGridListGetItemText(layergrid,curpos-r+1,3)
			local r2_text3 = dgsGridListGetItemText(layergrid,curpos-r+1,4)
			
			
			--
			dgsGridListSetItemData(layergrid,curpos-r+1,1,r1_data)
			dgsGridListSetItemData(layergrid,curpos-r+1,2,r1_data2)
			dgsGridListSetItemText(layergrid,curpos-r+1,2,r1_text)
			dgsGridListSetItemText(layergrid,curpos-r+1,3,r1_text2)
			dgsGridListSetItemText(layergrid,curpos-r+1,4,r1_text3)
			--
			dgsGridListSetItemData(layergrid,curpos-r,1,r2_data)
			dgsGridListSetItemData(layergrid,curpos-r,2,r2_data2)
			dgsGridListSetItemText(layergrid,curpos-r,2,r2_text)
			dgsGridListSetItemText(layergrid,curpos-r,3,r2_text2)
			dgsGridListSetItemText(layergrid,curpos-r,4,r2_text3)
		end
	end
end

p.s. for i = 1,10 works however for i = 10,1 is not

pp.s. i used thisdp's DX Gui system for this action

Link to comment
46 minutes ago, NeXuS™ said:

What do you mean by "for i = 10,1"?

He wants to loop with index starting from 10 to 1,
 

1 hour ago, JeViCo said:

Hello everyone! Could you help me with this? I tried to make it but it doesn't work properly (at all)

Any way you cant do it by this way,
Try this:

 

function moveToFirst(curpos)
	--local curpos = 5
	for r = 1, curpos do
		r = ( curpos + 1 ) - r;
		--print(r)
		if r == curpos then
			dgsGridListSetItemText(layergrid,1,1,"#1")
			dgsGridListSetItemText(layergrid,r,1,"#"..r)
		else
			local r1_data = dgsGridListGetItemData(layergrid,curpos-r,1) -- 4
			local r1_data2 = dgsGridListGetItemData(layergrid,curpos-r,2)
			--
			local r1_text = dgsGridListGetItemText(layergrid,curpos-r,2)
			local r1_text2 = dgsGridListGetItemText(layergrid,curpos-r,3)
			local r1_text3 = dgsGridListGetItemText(layergrid,curpos-r,4)
			--
			local r2_data = dgsGridListGetItemData(layergrid,curpos-r+1,1) -- 5
			local r2_data2 = dgsGridListGetItemData(layergrid,curpos-r+1,2)
			--
			local r2_text = dgsGridListGetItemText(layergrid,curpos-r+1,2)
			local r2_text2 = dgsGridListGetItemText(layergrid,curpos-r+1,3)
			local r2_text3 = dgsGridListGetItemText(layergrid,curpos-r+1,4)
			
			
			--
			dgsGridListSetItemData(layergrid,curpos-r+1,1,r1_data)
			dgsGridListSetItemData(layergrid,curpos-r+1,2,r1_data2)
			dgsGridListSetItemText(layergrid,curpos-r+1,2,r1_text)
			dgsGridListSetItemText(layergrid,curpos-r+1,3,r1_text2)
			dgsGridListSetItemText(layergrid,curpos-r+1,4,r1_text3)
			--
			dgsGridListSetItemData(layergrid,curpos-r,1,r2_data)
			dgsGridListSetItemData(layergrid,curpos-r,2,r2_data2)
			dgsGridListSetItemText(layergrid,curpos-r,2,r2_text)
			dgsGridListSetItemText(layergrid,curpos-r,3,r2_text2)
			dgsGridListSetItemText(layergrid,curpos-r,4,r2_text3)
		end
	end
end

Good luck

Edited by iMr.WiFi..!
Link to comment

i tried. Text and player's data is fine now but rows' data is reversed somehow =D

function moveTable(curpos)
	for m = 1, curpos do
		r = ( curpos + 1 ) - m
		-- добавка
		if r-1 > 0 then
			local r1_data = dgsGridListGetItemData(layergrid,r,1) -- привязка к номеру
			local r1_data2 = dgsGridListGetItemData(layergrid,r,1) -- привязка к номеру
			--local r1_text1 = dgsGridListGetItemText(layergrid,r,1)
			local r1_text2 = dgsGridListGetItemText(layergrid,r,2)
			local r1_text3 = dgsGridListGetItemText(layergrid,r,3)
			local r1_text4 = dgsGridListGetItemText(layergrid,r,4)
			-- добавка 2
			local r2_data = dgsGridListGetItemData(layergrid,r-1,1) -- привязка к номеру
			local r2_data2 = dgsGridListGetItemData(layergrid,r-1,1) -- привязка к номеру
			--local r2_text1 = dgsGridListGetItemText(layergrid,r-1,1)
			local r2_text2 = dgsGridListGetItemText(layergrid,r-1,2)
			local r2_text3 = dgsGridListGetItemText(layergrid,r-1,3)
			local r2_text4 = dgsGridListGetItemText(layergrid,r-1,4)
			--
			dgsGridListSetItemData(layergrid,r-1,1,r1_data)
			dgsGridListSetItemData(layergrid,r-1,2,r1_data2)
			--dgsGridListSetItemText(layergrid,r-1,1,r1_text1)
			dgsGridListSetItemText(layergrid,r-1,2,r1_text2)
			dgsGridListSetItemText(layergrid,r-1,3,r1_text3)
			dgsGridListSetItemText(layergrid,r-1,4,r1_text4)
			--
			dgsGridListSetItemData(layergrid,r,1,r2_data)
			dgsGridListSetItemData(layergrid,r,2,r2_data2)
			--dgsGridListSetItemText(layergrid,r,1,r2_text1)
			dgsGridListSetItemText(layergrid,r,2,r2_text2)
			dgsGridListSetItemText(layergrid,r,3,r2_text3)
			dgsGridListSetItemText(layergrid,r,4,r2_text4)
			--
			local k = getElementData(localPlayer,"player:data")
			local mid = k[m-1]
			k[m-1] = k[m]
			k[m] = mid
			setElementData(localPlayer,"player:data",k)
		end
	end
end

 

Link to comment
7 minutes ago, iMr.WiFi..! said:

So you want that Text, and Data reversed, but you want that rows show without reverse

not really. Ok, forget about rows - concentrate on tables. table.insert adds value to the end of table right?. I want to add this value and then drag it on first place without replacing it (all other values will move forwards by 1 step)

Edited by JeViCo
Link to comment

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...