[c#]
private void InitFlyGrid(FlyGrid flyGrid)
{
flyGrid.BeginInit();//freeze flyGrid updates
try
{
//add columns to FlyGrid
AddColumns(flyGrid);
//add nodes an fill cells
AddRows(flygrid);
}
finally
{
flyGrid.EndInit();//unfreeze and update flyGrid
}
}
private void AddColumns(FlyGrid flyGrid)
{
//clear existing columns
flyGrid.Columns.Items.Clear();
//create empty array of columns for addition to FlyGrid
Column[] cols = new Column[3];
for(int i=0; i < cols.Length; i++)
{
//create new column
cols[i] = new Column("column " + i.ToString());
//here you can specify some properties of created column
//....
}
//add columns
flyGrid.Columns.Items.AddRange(cols);
}
private void AddRows(FlyGrid flyGrid)
{
//clear existing rows
flyGrid.Rows.Items.Clear();
//create empty array of nodes for addition to FlyGrid
Node[] nodes = new Node[3];
for(int i=0; i < nodes.Length; i++)
{
//initialize cell values array
object[] cellValues = new object[flyGrid.Columns.Items.Count];
for(int j=0; j < cellValues.Length; j++)
{
//initialize cell value with "cell row, col" value
cellValues[j] = string.Format("cell {0},{1}", i, j);
}
//create new node/row
nodes[i] = new Node(cellValues)
}
//add nodes to flyGrid
flyGrid.Rows.Items.AddRange(nodes);
}