views:

361

answers:

3
+4  Q: 

Int To String?

Hello,

I have a listView on my form.I want to add stuff to it durring the program is running.

This is the code I use

    public void FillList(string[] Name,int[] empty,int[] Population,int[] Max,int[] Check,int size)
    {
        if (this.InvokeRequired)
        {
            this.Invoke((MethodInvoker)delegate
            {
                for (int i = 0; i < size; i++)
                {
                    ListViewItem item = new ListViewItem(Name[i]);

                    item.SubItems.Add(empty[i].ToString); //error
                    item.SubItems.Add(Population[i].ToString); //error
                    item.SubItems.Add(Max[i].ToString);   //error

                    if (Check != 1)
                        item.SubItems.Add("No");
                    else
                        item.SubItems.Add("Yes");
                    listView1.Items.Add(item);
                }
            });
        }
    }

the parameter must be string and I tried .ToString,but I get this:

Argument '1': cannot convert from 'method group' to 'string'

+18  A: 

You miss the parentheses:

ToString()

Konrad Rudolph
(except without the exclamations...!!)
ck
You should have flagged this question as offensive (to the eye) :D
Peter Perháč
It is a lot of work to go on SO and ask this sort of question...at least he got a quick answer.
Mark Brittingham
Yeah, We all have moments like this.....At least I do :P
Damien
Been there done that :D
cwap
+5  A: 

You forgot the parentheses.

It should be .ToString()

Rik
A: 

John this is off topic but have you considered with this method to pass in a class made up of each of the sub items to add. So:

class ListItem 
{
 public string Name {get; set;}
 public int Empty {get; set;}
 public int Population {get; set;}
 public int Max {get; set;}
 public bool Checked {get; set;}
}

That way you would need to have each of the items in the arrays passed in lined up. Trying to line up items in many arrays often make interfaces hard to use. Your method would look like

FillList(IList<ListItem> listItems)
{
if (this.InvokeRequired)
    {
        this.Invoke((MethodInvoker)delegate
        {
            foreach (ListItem listItem in listItems)
            {
                ListViewItem item = new ListViewItem(listItem .Name);

                item.SubItems.Add(listItem.Empty.ToString());
                item.SubItems.Add(listItem.Population.ToString());
                item.SubItems.Add(listItem.Max.ToString());

                item.SubItems.Add(listItem.Checked ? "No" : "Yes");

                listView1.Items.Add(item);
            }
        }
    }
}

I've just written this code straight in so there maybe some code cleanup required

Jiminy