Add an empty column in WPF GridView - wpf

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...

Maybe use an empty CellTemplate?
<GridViewColumn Width="100">
<GridViewColumn.CellTemplate>
<DataTemplate />
</GridViewColumn.CellTemplate>
</GridViewColumn>

Or just don't specify anything...
<GridViewColumn Header="Col 3" Width="500" />

Related

How to bind double click on row to command in GridView that inside ListView in MVVM WPF

I'm prrety new to wpf, and i try to make a GridView that inside ListView to response to double click on row in the view
I try to make this-
<ListView
ItemsSource="{Binding Products}">
<ListView.InputBindings>
<MouseBinding
MouseAction="LeftDoubleClick"
Command="{Binding Test}" />
</ListView.InputBindings>
<ListView.View>
<GridView>
</GridView.ColumnHeaderContainerStyle>
<GridViewColumn
Header="ID"
DisplayMemberBinding="{Binding ID}" />
<GridViewColumn
Header="Name"
DisplayMemberBinding="{Binding Name}" />
<GridViewColumn
Header="Category"
DisplayMemberBinding="{Binding Category}" />
<GridViewColumn
Header="Price"
DisplayMemberBinding="{Binding Price}" />
</GridView>
</ListView.View>
<ListView />
when Test is an ICommand property in the view model.
But it's not responding to double click.
What am I getting wrong, and mabye there is another way?

How to add several Checkboxs columns

I have ListView binding with my collection:
private List<MyData> Col;
ItemsSource="{Binding Col}"
I define this inside my ListView:
<ListView.View>
<GridView>
<GridView.Columns>
<GridViewColumn Header="Selected">
<GridViewColumn.CellTemplate>
<DataTemplate>
<CheckBox x:Name="cbSelect" IsChecked="{Binding SupportedVendors}" />
</DataTemplate>
</GridViewColumn.CellTemplate>
</GridViewColumn>
<GridViewColumn DisplayMemberBinding="{Binding Name}" Header="Name" Width="100"/>
<GridViewColumn DisplayMemberBinding="{Binding ID}" Header="ID" Width="600"/>
</GridView.Columns>
</GridView>
</ListView.View>
Now i want channge my object bool value inside my Collcection once the user change the CheckBox.
I can i do that ? (i need it in code behaind)
Tag the object of your collection with the CheckBox, the on check /uncheck you can get the tag from the checkbox checked. Change the bool value in the object.

WPF: When Adding items to a listview they become empty

Im a bit new to WPF and I cant seem to figure out why the items I add to a listview are displaying empty.
Here is my XAML
<ListView.View>
<GridView>
<GridViewColumn Header="ID" Width="30" DisplayMemberBinding="{Binding Source={StaticResource BillingIncrements}, Path=ID}" />
<GridViewColumn Header="Bill Group" DisplayMemberBinding="{Binding Source={StaticResource BillingIncrements}, Path=Description}" />
</GridView>
</ListView.View>
Here is the code
lstBillGroups.Items.Add(New StlReportPlugins.BillingIncrements With {.ID = 100, .Description = "Test"})
Here is the output
(couldnt post a pic because i dont have enough points)
Link to pic
Any Ideas?
This is how your XAML should look like
<ListView ItemsSource={Binding Source={StaticResource BillingIncrements}}>
<ListView.View>
<GridView>
<GridViewColumn Header="ID" Width="30" DisplayMemberBinding="{Binding ID}" />
<GridViewColumn Header="Bill Group" DisplayMemberBinding="{Binding Description}"/>
</GridView>
</ListView.View>
</ListView>
If you have a look at output window in VS while debugging your app you'll see a bunch of WPF binding errors, which helps a lot to spot mistakes.

Checkbox is not displaying in rows from ListView

I created list view with check box at column 1, but it's displaying only at header level and in rows i'm getting namespace name.
Here's the XAML code:
<ListView x:Name="ConfigurationFilesGrid" ItemsSource="{Binding ConfigurationFiles}"
SelectedItem="{Binding SelectedProgramFile}"
ScrollViewer.CanContentScroll="True"
PreviewMouseDoubleClick="ConfigurationFilesGrid_Reselect"
>
<ListView.View>
<GridView>
<GridViewColumn>
<GridViewColumn.HeaderTemplate>
<DataTemplate>
<CheckBox HorizontalAlignment="Center" VerticalAlignment="Center" IsChecked="{Binding ElementName=ConfigurationMainCtrl, Path=DataContext.IsAllConfigurationSelected}"/>
</DataTemplate>
</GridViewColumn.HeaderTemplate>
</GridViewColumn>
<GridViewColumn Header="{x:Static res:Resources.IDColNameTxt}" DisplayMemberBinding="{Binding ID}" />
<GridViewColumn Header="{x:Static res:Resources.TypeColHdr}" DisplayMemberBinding="{Binding DisplayType}" />
<GridViewColumn Header="{x:Static res:Resources.NameColNameTxt}" DisplayMemberBinding="{Binding Name}"/>
<GridViewColumn Header="{x:Static res:Resources.MeterColNameTxt}" DisplayMemberBinding="{Binding MeterType}"/>
<GridViewColumn Header="{x:Static res:Resources.RateColNameTxt}" DisplayMemberBinding="{Binding RateDisplay}"/>
<GridViewColumn Header="{x:Static res:Resources.CommentColNameTxt}" DisplayMemberBinding="{Binding Comment}"/>
<GridViewColumn Header="{x:Static res:Resources.ModifiedDateColNameTxt}" DisplayMemberBinding="{Binding ModifiedDateTime}"/>
<GridViewColumn Header="{x:Static res:Resources.ProfileColNameTxt}" DisplayMemberBinding="{Binding Profile}"/>
</GridView>
</ListView.View>
</ListView>
And i'm getting list view like:
[](checkbox) ID Name Address
name 1 A X
name 2 B Y
But from above i'm getting checkbox only at header level not rows level so what change 'll reflect to checkbox from above xaml code.
Thanks for you help.
Nag
You've used the HeaderTemplate of the GridViewColumn, use the CellTemplate instead:
<GridViewColumn>
<GridViewColumn.CellTemplate>
<DataTemplate>
<CheckBox HorizontalAlignment="Center" VerticalAlignment="Center" IsChecked="{Binding ElementName=ConfigurationMainCtrl, Path=DataContext.IsAllConfigurationSelected}"/>
</DataTemplate>
</GridViewColumn.CellTemplate>
</GridViewColumn>

Add row in multiple-column listview?

I am having trouble adding a row that displays all the values of the member of an object.
Here is how I have set up my listview:
<ListView Height="178" HorizontalAlignment="Left" Margin="238,31,0,0" Name="SpoolSheetListView" VerticalAlignment="Top" Width="555" HorizontalContentAlignment="Stretch" SelectionMode="Single">
<ListView.View>
<GridView>
<GridViewColumn Width="85" Header="Column 1" />
<GridViewColumn Width="120" Header="Column 2" />
<GridViewColumn Width="120" Header="Column 3" />
<GridViewColumn Width="120" Header="Column 4" />
<GridViewColumn Width="115" Header="Column 5" />
</GridView>
</ListView.View>
</ListView>
say, myObject has 5 members: member1 to member5, which are all of type string. How do I add a single row in the ListView for that object?
Thanks again people!
WPF list controls work best when you use them with data binding; you should bind the ItemsSource of the ListView to a list of objects, and bind each column to a property of these objects.
<ListView ItemsSource="{Binding Items}" Height="178" HorizontalAlignment="Left" Margin="238,31,0,0" Name="SpoolSheetListView" VerticalAlignment="Top" Width="555" HorizontalContentAlignment="Stretch" SelectionMode="Single">
<ListView.View>
<GridView>
<GridViewColumn Width="85" Header="Column 1" DisplayMemberBinding="{Binding Member1}" />
<GridViewColumn Width="120" Header="Column 2" DisplayMemberBinding="{Binding Member2}" />
<GridViewColumn Width="120" Header="Column 3" DisplayMemberBinding="{Binding Member3}" />
<GridViewColumn Width="120" Header="Column 4" DisplayMemberBinding="{Binding Member4}" />
<GridViewColumn Width="115" Header="Column 5" DisplayMemberBinding="{Binding Member5}" />
</GridView>
</ListView.View>
</ListView>
(Items being a property of the DataContext that returns a collection of objects)
To add a row to the ListView, you just need to add an item to the Items collection (note that the collection should implement INotifyCollectionChanged so that the ListView is notified; the ObservableCollection<T> class works fine for most cases)

Resources