# Best way to populate a datagrid dynamically in as 3?

**URL:** <https://forum.kirupa.com/t/best-way-to-populate-a-datagrid-dynamically-in-as-3/269033>\
**Category:** Uncategorized\
**Created:** [August 21, 2008, 4:30pm UTC](https://forum.kirupa.com/t/best-way-to-populate-a-datagrid-dynamically-in-as-3/269033 "2008-08-21T16:30:25Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![chrisef](https://avatars.discourse-cdn.com/v4/letter/c/8baadc/32.png) [@chrisef](https://forum.kirupa.com/u/chrisef)\
**Post date:** [August 21, 2008, 4:30pm UTC](https://forum.kirupa.com/t/best-way-to-populate-a-datagrid-dynamically-in-as-3/269033/1 "2008-08-21T16:30:25Z")

</div>

Hi all

I’m building a datagrid and came up with this clunky code to populate rows and columns.

Can anyone suggest a better code method than this overlong if/else loop?

Thanks for looking.

Chris.

```auto
for (var j:int = 0; j < xmlList.length(); j++) {
		
           var rowRate=0;
		totWidth = j*145/reqRows;
		ySet = rowRate*89+5;
		colCount+=1;
		
		var myVar = colCount/4;
		
			//1
	[COLOR="Green"]	if (rowRate>=4 && rowRate<8) {
			xSet = 150;
			ySet -= 356;
			//2
		} else if (rowRate>=8 && rowRate<12) {
			xSet = 295;
			ySet -= 712;
			//3
		} else if (rowRate>=12 && rowRate<16) {
			xSet = 440;
			ySet -= 1068;
			//4
		} else if (rowRate>=16 && rowRate<20) {
			xSet = 585;
			ySet -= 1424;[/COLOR]
			//5
		} 

```
