1) ... and remove update void
2) set sorted to true on UIGrid
3) call reposition on grid
4) ResetPosition on panel
i have similar method used with Table and works.
// Use this for initialization
void Start ()
{
GlobalEditorData
.cells = new TSourceCell
[this.cellWidth,
this.cellHeight];
this.table = NGUITools.FindInParents<UITable>(this.gameObject);
this.panel = NGUITools.FindInParents<UIDraggablePanel>(table.gameObject);
table.sorted = true;
this.table.columns = this.cellWidth;
// rename objects to standard matrix direction from left -> right and from top -> down
int idx = 0;
for (int y=0;y<this.cellHeight;y++)
for (int x=0;x<this.cellWidth;x++)
{
int cx = x;
int cy = y;
GlobalEditorData
.cells[cx,cy
] = new TSourceCell
();
GameObject cell = NGUITools.AddChild(this.gameObject,this.itemPrefab);
string name_cell = string.Format("{0:0000}",idx);
GlobalEditorData.cells[cx,cy].name = name_cell;
GlobalEditorData.cells[cx,cy].item = cell;
GlobalEditorData.cells[cx,cy].item.name = name_cell;
string path = "/UI Root (2D)/Camera/Anchor/Source_Window/SourcePanelEmpty/SourceTable/"+GlobalEditorData.cells[cx,cy].item.name+"/ButtonEmpty_CMD";
GameObject o = GameObject.Find(path);
GlobalEditorData.cells[cx,cy]._cmd = (OnClick_SourceCell)o.GetComponent<OnClick_SourceCell>();
GlobalEditorData.cells[cx,cy]._cmd.parentName = GlobalEditorData.cells[cx,cy].item.name;
GlobalEditorData.cells[cx,cy]._cmd.label.text = cx.ToString()+"x"+cy.ToString();
GlobalEditorData.cells[cx,cy].icon = (UISlicedSprite)GlobalEditorData.cells[cx,cy]._cmd.GetComponentInChildren<UISlicedSprite>();
idx++;
}
this.table.Reposition();
this.panel.ResetPosition();
}