views:

3422

answers:

2

Even if I know it's not ideal - I need to programmatically populate a listView (for whatever reason).

I am declaring my columns in the markup:

            <ListView.View>
                <GridView>
                    <GridViewColumn Header="Name" DisplayMemberBinding="{Binding Path=Name}"/>
                    <GridViewColumn Header="Value" DisplayMemberBinding="{Binding Path=Value}"/>
                </GridView>
            </ListView.View>

I am adding the items like this in code (it's obviously in a loop):

            MyData data = getDataItem(index); //< -- whatever
            ListViewItem item = new ListViewItem();
            item.DataContext = data;
            this.myListView.Items.Add(item);

Where MyData is defined as:

public class MyData
{
    public string Name { get; set; }
    public string Value { get; set; }
}

The items are being added (I can see the rows) but I don't see any content.

Anyone any clue?

Any help appreciated!

+4  A: 

It works changing the code to:

        MyData data = getDataItem(index); //< -- whatever
        this.myListView.Items.Add(data);

Now it looks obvious but ... go figure!

JohnIdol
+1  A: 

Hey Thank helped me a lot today... But now i dont know how to add ToolTip to those and I realy need it...

Evgeny
I suggest you ask a new question for the tooltip stuff. I am sure my nerdiezz will help you out.
JohnIdol