- Home /
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..
Answer by hatshapedhat · Mar 01, 2013 at 01:41 AM
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;
}
That worked! Changed the first line to:`customerGridNames = new string[Customer$$anonymous$$anager.Customers.Count];` I am guessing thats what you meant.
Thanks!!
Your answer
![](https://koobas.hobune.stream/wayback/20220613093617im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
A node in a childnode? 1 Answer
Easiest way to create an inventory system? 2 Answers
Plz Need Help 1 Answer