T
Tony Johansson
Hello!
Here is the code that update the listBox but there is a small problem. When
I have different number of item in the foodList will the position for the
column title not be lined up the the data. How do I best solve this lined up
between the column title and the data for the corresponding column ?
public void UpdateGUI()
{
bool flag = false;
lstOutput.Items.Clear();
foreach (Animal animal in animalManager.Animals.ToArray())
{
string foodList = string.Join(",",
animal.FoodMenyList.ToArray());
if (!flag)
{
lstOutput.Items.Add(string.Format("{0}{1,16}{2,29}{3,22}{4,18}{5,35}{6,35}{7,20}{8,20}",
"Animal", "ID", "Name", "Age", "Gender", "Food items",
"Aggressive", "Housing", "Special data"));
lstOutput.Items.Add(string.Empty);
flag = true;
}
lstOutput.Items.Add(string.Format("{0}{1,27}{2,17}{3,20}{4,22}{5,40}{6,21}{7,29}{8,23}",
animal.MyAnimal, animal.ID, animal.Name,
animal.Age,animal.Gender, foodList,
animal.Aggressive,animal.Housing,"No Extra Info"));
}
}
//Tony
Here is the code that update the listBox but there is a small problem. When
I have different number of item in the foodList will the position for the
column title not be lined up the the data. How do I best solve this lined up
between the column title and the data for the corresponding column ?
public void UpdateGUI()
{
bool flag = false;
lstOutput.Items.Clear();
foreach (Animal animal in animalManager.Animals.ToArray())
{
string foodList = string.Join(",",
animal.FoodMenyList.ToArray());
if (!flag)
{
lstOutput.Items.Add(string.Format("{0}{1,16}{2,29}{3,22}{4,18}{5,35}{6,35}{7,20}{8,20}",
"Animal", "ID", "Name", "Age", "Gender", "Food items",
"Aggressive", "Housing", "Special data"));
lstOutput.Items.Add(string.Empty);
flag = true;
}
lstOutput.Items.Add(string.Format("{0}{1,27}{2,17}{3,20}{4,22}{5,40}{6,21}{7,29}{8,23}",
animal.MyAnimal, animal.ID, animal.Name,
animal.Age,animal.Gender, foodList,
animal.Aggressive,animal.Housing,"No Extra Info"));
}
}
//Tony