Adding "sub items" to listview
- Hi all,
i have a list view with tree columns and i need to add items to it like this
------------------------------------------
Name | Manufacturer | Cost
------------------------------------------
Honda City | Honda | n$
Honda Civic | Honda | n$
Ford Icon | Ford | n$
------------------------------------------
but im struck while adding Columns to it.i could not find ListViewItem.SubItem to add...
can any one help me doing it.
bals
Réponses
thank you geert van and Rahul,
i just did it by refering the this site : http://www.switchonthecode.com/tutorials/wpf-tutorial-using-the-listview-part-1
this is what exactly iwanted to do.
bals- Proposé comme réponseGeert van Horrik jeudi 5 novembre 2009 08:23
- Marqué comme réponseBruce.ZhouMSFT, Modérateurlundi 9 novembre 2009 02:16
- Hi,
Create a DataTemmpate with Grid inside it. Divide this Grid into 3 coulmns and then for each column put the TextBlocks bind with the concerned input values.
<Window.Resources>
<DataTemplate x:Key="EmpData">
<Grid Width="300" ShowGridLines="True">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="60"></ColumnDefinition>
<ColumnDefinition Width="100"></ColumnDefinition>
<ColumnDefinition Width="60"></ColumnDefinition>
<ColumnDefinition Width="60"></ColumnDefinition>
</Grid.ColumnDefinitions>
<TextBlock Text="{Binding Path=EmpNo}" Grid.Column="0"></TextBlock>
<TextBlock Text="{Binding Path=EmpName}" Grid.Column="1"></TextBlock>
<TextBlock Text="{Binding Path=DeptNo}" Grid.Column="2" TextAlignment="Center"></TextBlock>
<TextBlock Text="{Binding Path=Salary}" Grid.Column="3"></TextBlock>
</Grid>
</DataTemplate>
</Window.Resources>
<Grid Width="300">
<ListView Margin="4,17,20,0" Name="listBox1" Width="300"
ItemsSource="{Binding}" ItemTemplate="{StaticResource EmpData}"/>
</Grid>
Mahesh Sabnis- Proposé comme réponseGeert van Horrik mercredi 4 novembre 2009 15:28
- Marqué comme réponseBruce.ZhouMSFT, Modérateurlundi 9 novembre 2009 02:16
Toutes les réponses
- In your listview, there is a ListView.View property. Put a GridView in there.
A detailed explanation can be found in this blog article.
Geert van Horrik - CatenaLogic
Visit my blog: http://blog.catenalogic.com
Looking for a way to deploy your updates to all your clients? Try Updater! - Hi,
See if it is something like this you are looking for .
By default you want get such an option.You will have to change the templates,so as to suite your requirement.
The above representation doesnt make it clear to me on how you want the data to be.I see only a single level of data.
Could you please make it more clear so that i may be of more help
Thank You
Please mark posts as answers/helpful if it answers your query. This would be helpful for others facing the same kind of problem thank you geert van and Rahul,
i just did it by refering the this site : http://www.switchonthecode.com/tutorials/wpf-tutorial-using-the-listview-part-1
this is what exactly iwanted to do.
bals- Proposé comme réponseGeert van Horrik jeudi 5 novembre 2009 08:23
- Marqué comme réponseBruce.ZhouMSFT, Modérateurlundi 9 novembre 2009 02:16
- Hi,
Create a DataTemmpate with Grid inside it. Divide this Grid into 3 coulmns and then for each column put the TextBlocks bind with the concerned input values.
<Window.Resources>
<DataTemplate x:Key="EmpData">
<Grid Width="300" ShowGridLines="True">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="60"></ColumnDefinition>
<ColumnDefinition Width="100"></ColumnDefinition>
<ColumnDefinition Width="60"></ColumnDefinition>
<ColumnDefinition Width="60"></ColumnDefinition>
</Grid.ColumnDefinitions>
<TextBlock Text="{Binding Path=EmpNo}" Grid.Column="0"></TextBlock>
<TextBlock Text="{Binding Path=EmpName}" Grid.Column="1"></TextBlock>
<TextBlock Text="{Binding Path=DeptNo}" Grid.Column="2" TextAlignment="Center"></TextBlock>
<TextBlock Text="{Binding Path=Salary}" Grid.Column="3"></TextBlock>
</Grid>
</DataTemplate>
</Window.Resources>
<Grid Width="300">
<ListView Margin="4,17,20,0" Name="listBox1" Width="300"
ItemsSource="{Binding}" ItemTemplate="{StaticResource EmpData}"/>
</Grid>
Mahesh Sabnis- Proposé comme réponseGeert van Horrik mercredi 4 novembre 2009 15:28
- Marqué comme réponseBruce.ZhouMSFT, Modérateurlundi 9 novembre 2009 02:16
- Hi,
So here actually there is no SubItems :)
It was just that you wanted to add items to the listview :)
Anyways good that your problem is solved
Please mark posts as answers/helpful if it answers your query. This would be helpful for others facing the same kind of problem - yes,there is no subitems.
im confused with windows forms controls with WPF.
wpf is quite different with those controls.i think it takes a while for me to be confortable with WPF :)
bals

