kmarks2
kmarks2

Reputation: 4885

Finding the easiest way to display rows of data in WPF

I have used WPF very little so I'm looking for the simplest most straightforward way to accomplish this task.

Basically I have a Dictionary where the key is some identifier, and the value is a description. I wish to display a grid/listview of the descriptions with the intention of adding/removing rows by their non-displayed identifier.

How can this be accomplished quickly and easily?

Upvotes: 2

Views: 437

Answers (2)

paparazzo
paparazzo

Reputation: 45106

Sample code binding to a dictionary list. To display the value replace Key with Value. Dictionary is not an observable collection so the UI will not dynamically pick up inserts and deletes.

<ListView ItemsSource="{Binding Path=GabeLib.DLFTSwordReverse, Mode=OneWay}" DisplayMemberPath="Key" 
                                      VirtualizingStackPanel.IsVirtualizing="True" VirtualizingStackPanel.VirtualizationMode="Recycling" ScrollViewer.IsDeferredScrollingEnabled="True"  
                                      ScrollViewer.HorizontalScrollBarVisibility="Disabled" ScrollViewer.VerticalScrollBarVisibility="Visible"/>

If you set Mode=TwoWay I think you could even update the Value.

Upvotes: 1

Artiom
Artiom

Reputation: 7847

You can't do that. To add the new row you need to set it. But in case of hidden Key column you won't accomplish this. In case you need just updating look here

Upvotes: 1

Related Questions