السلام عليكم 
ما الطريقة لترتيب الأعداد :
10
1
20
2
لتظهر مرتبة في العنصر
Grid من الاصغر إلى الأكبر
سلام
							
						
					ما الطريقة لترتيب الأعداد :
10
1
20
2
لتظهر مرتبة في العنصر
Grid من الاصغر إلى الأكبر
سلام
							
						
							
						Grid.SortTextItems("Grid1", 0, true, true);
function alphanumsort(o)
  local function padnum(d) local dec, n = string.match(d, "(%.?)0*(.+)")
    return #dec > 0 and ("%.12f"):format(d) or ("%s%03d%s"):format(dec, #n, n) end
  table.sort(o, function(a,b)
    return tostring(a):gsub("%.?%d+",padnum)..("%3d"):format(#b)
         < tostring(b):gsub("%.?%d+",padnum)..("%3d"):format(#a) end)
  return o
end 
my_table ={}
p=Grid.GetRowCount("Grid1");
for i=1,p do
c= Grid.GetCellText("Grid1", i-1, 0);
Table.Insert(my_table, i, c);
end
for k,v in ipairs(alphanumsort(my_table)) do 
Grid.SetCellText("Grid1", k-1, 0, v, true)
end 
my_table ={}
-----------------------------------------------
p=ListBox.GetCount("ListBox1");
for i=1,p do
 c= ListBox.GetItemText("ListBox1", i);
 Table.Insert(my_table, i, c);
end
Table.Sort(my_table, nil);
for k,v in  ipairs(alphanumsort(my_table)) do  
ListBox.SetItemText("ListBox1", k, v);
end 
							
						
n = Grid.GetRowCount("Grid1"); 
my_table = {};
for i = 1,n do 
v = Grid.GetCellText("Grid1", i-1, 0);
v= String.ToNumber(v);
Table.Insert(my_table, i, v);
end 
table.sort(my_table, function(a,b) return a>b end) 
for b , k in pairs(my_table) do
Grid.SetCellText("Grid1", b-1, 0, k, true) 
end 
n = ListBox.GetCount("ListBox1");
my_table = {};
for i = 1,n do 
v = ListBox.GetItemText("ListBox1", i)
v= String.ToNumber(v);
Table.Insert(my_table, i, v);
end 
table.sort(my_table, function(a,b) return a>b end) 
for b , k in pairs(my_table) do
ListBox.AddItem("ListBox1", k, "");
ListBox.DeleteItem("ListBox1", 1);
end 
							
						
n = grid.getrowcount("grid1"); 
my_table = {};
for i = 1,n do 
v = grid.getcelltext("grid1", i-1, 0);
v= string.tonumber(v);
table.insert(my_table, i, v);
end 
table.sort(my_table, function(a,b) return a>b end) 
for b , k in pairs(my_table) do
grid.setcelltext("grid1", b-1, 0, k, true) 
end 
n = listbox.getcount("listbox1");
my_table = {};
for i = 1,n do 
v = listbox.getitemtext("listbox1", i)
v= string.tonumber(v);
table.insert(my_table, i, v);
end 
table.sort(my_table, function(a,b) return a>b end) 
for b , k in pairs(my_table) do
listbox.additem("listbox1", k, "");
listbox.deleteitem("listbox1", 1);
end 

function alphanumsort(o)
  local function padnum(d) local dec, n = string.match(d, "(%.?)0*(.+)")
    return #dec > 0 and ("%.12f"):format(d) or ("%s%03d%s"):format(dec, #n, n) end
  table.sort(o, function(a,b)
    return tostring(a):gsub("%.?%d+",padnum)..("%3d"):format(#b)
         < tostring(b):gsub("%.?%d+",padnum)..("%3d"):format(#a) end)
  return o
end 
my_table ={}
p=grid.getrowcount("grid1");
for i=1,p do
c= grid.getcelltext("grid1", i-1, 0);
table.insert(my_table, i, c);
end
for k,v in ipairs(alphanumsort(my_table)) do 
grid.setcelltext("grid1", k-1, 0, v, true)
end 
my_table ={}
-----------------------------------------------
p=listbox.getcount("listbox1");
for i=1,p do
 c= listbox.getitemtext("listbox1", i);
 table.insert(my_table, i, c);
end
table.sort(my_table, nil);
for k,v in  ipairs(alphanumsort(my_table)) do  
listbox.setitemtext("listbox1", k, v);
end 

تعليق