Need to display strings in a List<> in a GUILayout.SelectionGrid

Hi,

I am trying to display the strings within a List in a GUILayout.Selection grid. Here is what I have, but its only displaying one of the customer names. How can I set strings of the selection grid to be the strings from my list?

		for(int cnt = 0; cnt < CustomerManager.Customers.Count; cnt++)
		{
			customerGridNames = new string[] {CustomerManager.Customers[cnt].name};
		}

	void SelectCustomerWindow(int windowID)
	{
		GUILayout.BeginScrollView(Vector2.right);
		//Selection grid with customer names showing
		selectedGrid = GUILayout.SelectionGrid(selectedGrid, customerGridNames, 1);
		GUILayout.EndScrollView();
	}

Hmm… Thought maybe I could convert my List to an array using CustomerManager.Customers.ToArray and just putting it right into the selection Grid but no dice…

Your for loop is wrong - for each Customer its making a new string array and setting the contents of that string array to the current iteration variable, so you will end up with an array that only contains your last customer.

Try something more like :

 customerGridNames = new string[](CustomerManager.Customers.Count);
 for(int cnt = 0; cnt < CustomerManager.Customers.Count; cnt++)
 {
    customerGridNames[cnt] = CustomerManager.Customers[cnt].name;
 }