Search code examples
c#objectlistview

ObjectListView - Displaying arrays


Suppose I have this code:

public sealed class MyStruct {
    // ... snip
    public uint[] ItemStatValue { get; set; }
    // ... snip
}

// MainForm.cs
// ...
Generator.GenerateColumns(this.ContentListView, structure, true);
ContentListView.SetObjects(_records);
// ...

Is there a way to instruct GenerateColumns to treat each element of the ItemStateValue property as a column on its own, and appropriately name them ? ("Item Stat Value 1", "Item Stat Value 2", etc) Currently, it just calls ToString() on the object, thus returning System.Type.UInt32[]. Not exactly what I'd want.

I'm using http://www.codeproject.com/Articles/16009/A-Much-Easier-to-Use-ListView

Cheers!


Solution

  • @Grammarian So after looking around in the code, I noticed aspect getters for fields. However, Generator.GenerateColumns didn't seem to use its third boolean parameter, named allProperties.

    So I threw together this quick code, and sure enough, it worked. It doesn't seem to cause any bug either, which is great.

    Here is a gist:

    https://gist.github.com/Warpten/c792ad66ad20cc69a918

    Note: this also requires that you allow OLVColumnAttribute and OLVIgnoreAttribute to be applied to fields. That's easy enough ;)

    Cheers!