Bashar C
Bashar C

Reputation: 147

Add an empty column in WPF GridView

I have a ListView (GridView) bound to a collection. For aesthetic reason, I want an empty column at the beginning. If I do

<ListView.View>
    <GridView>
        <GridViewColumn Width="100" />
        <GridViewColumn Header="Col 1" DisplayMemberBinding="{Binding P1}" />
        <GridViewColumn Header="Col 2" DisplayMemberBinding="{Binding P2}" />
        <GridViewColumn Header="Col 3" DisplayMemberBinding="{Binding P3}" />
    </GridView>
</ListView.View>

I get the .ToString() of the ItemSource in the first column. I just want an empty column, and I do not want to bind to an empty string property. Any idea?

I just hope it is not too obvious...

Upvotes: 1

Views: 1792

Answers (3)

bytecode77
bytecode77

Reputation: 14860

Even better than a DataTemplate, use {x:Null} as a binding.

<GridViewColumn Header="Empty Column" DisplayMemberBinding="{Binding Source={x:Null}}" />

Defining a DataTemplate is verbose and causes lagging when scrolling through a ListView with many items.

Upvotes: 0

Faraday
Faraday

Reputation: 2954

Or just don't specify anything...

<GridViewColumn Header="Col 3" Width="500" />

Upvotes: -1

McGarnagle
McGarnagle

Reputation: 102793

Maybe use an empty CellTemplate?

    <GridViewColumn Width="100"> 
        <GridViewColumn.CellTemplate>
            <DataTemplate />
        </GridViewColumn.CellTemplate>
    </GridViewColumn> 

Upvotes: 8

Related Questions