How to add multiple column in a single column of gridview in WPF?
-
Hi All, I am able to add column into a gridview as follows: <ListView Name="listView1" ItemsSource="{Binding}" Margin="11,26,115,44"> <ListView.View > <GridView > <GridViewColumn Header="ID" DisplayMemberBinding="{Binding ID}" /> <GridViewColumn Header="Span Length" DisplayMemberBinding="{Binding Span Length}" /> </GridView> </ListView.View> </ListView > but i want to add multiple column into a single column in the abovew grid view i mean that, i have create some groups to show data into single gridview. can anybody help me how it is possible because i am new with xaml... Thanks Bankey
-
Hi All, I am able to add column into a gridview as follows: <ListView Name="listView1" ItemsSource="{Binding}" Margin="11,26,115,44"> <ListView.View > <GridView > <GridViewColumn Header="ID" DisplayMemberBinding="{Binding ID}" /> <GridViewColumn Header="Span Length" DisplayMemberBinding="{Binding Span Length}" /> </GridView> </ListView.View> </ListView > but i want to add multiple column into a single column in the abovew grid view i mean that, i have create some groups to show data into single gridview. can anybody help me how it is possible because i am new with xaml... Thanks Bankey
Do you mean you want to show multiple bound items in a GridViewColumn? If so, you can bind multiple items into a data template like this:
<DataTemplate>
<TextBlock>
<TextBlock Text="{Binding Path=...}" />
<TextBlock Text="{Binding Path=...}" />
</TextBlock>
</DataTemplate>Deja View - the feeling that you've seen this post before.
-
Do you mean you want to show multiple bound items in a GridViewColumn? If so, you can bind multiple items into a data template like this:
<DataTemplate>
<TextBlock>
<TextBlock Text="{Binding Path=...}" />
<TextBlock Text="{Binding Path=...}" />
</TextBlock>
</DataTemplate>Deja View - the feeling that you've seen this post before.
Here are two other ways you can do this. 1. Use a MultiValue Converter that concatenates the two strings and places the output in one TextBlock. I demonstrate this techniques in my article: http://www.codeproject.com/KB/WPF/WPFBusinessAppsPartThree.aspx[^]. This article also has the required value converter code and xaml usage. Look at the below xaml. See how the MultiBinding Converter syntax works, it takes muliple string values and binding them to one property. MultiBinding converters are a great WPF feature.
<Core_WPF:FormNotification WatermarkMessage="New Record"
Height="28" Panel.ZIndex="99" AutoCollapseTimeout="2">
<Core_WPF:FormNotification.ErrorMessage>
<MultiBinding Converter="{StaticResource formNotificationErrorMessageConverter}">
<Binding Path="Error" />
<Binding Path="ValidationExceptionErrors" ElementName="ucPartThree" />
</MultiBinding>
</Core_WPF:FormNotification.ErrorMessage>
</Core_WPF:FormNotification>2. In addition to Pete's code of placing the two TextBlocks inside another TextBlock, you could also use a StackPanel as a container for the two TextBlocks.
Cheers, Karl
» CodeProject 2008 MVP » Microsoft MVP - Client App Dev My Blog | Mole's Home Page | MVP ProfileJust a grain of sand on the worlds beaches.
-
Here are two other ways you can do this. 1. Use a MultiValue Converter that concatenates the two strings and places the output in one TextBlock. I demonstrate this techniques in my article: http://www.codeproject.com/KB/WPF/WPFBusinessAppsPartThree.aspx[^]. This article also has the required value converter code and xaml usage. Look at the below xaml. See how the MultiBinding Converter syntax works, it takes muliple string values and binding them to one property. MultiBinding converters are a great WPF feature.
<Core_WPF:FormNotification WatermarkMessage="New Record"
Height="28" Panel.ZIndex="99" AutoCollapseTimeout="2">
<Core_WPF:FormNotification.ErrorMessage>
<MultiBinding Converter="{StaticResource formNotificationErrorMessageConverter}">
<Binding Path="Error" />
<Binding Path="ValidationExceptionErrors" ElementName="ucPartThree" />
</MultiBinding>
</Core_WPF:FormNotification.ErrorMessage>
</Core_WPF:FormNotification>2. In addition to Pete's code of placing the two TextBlocks inside another TextBlock, you could also use a StackPanel as a container for the two TextBlocks.
Cheers, Karl
» CodeProject 2008 MVP » Microsoft MVP - Client App Dev My Blog | Mole's Home Page | MVP ProfileJust a grain of sand on the worlds beaches.
Karl - that's the thing I really love about WPF. So many ways to solve the same problem, all of them flexible.
Deja View - the feeling that you've seen this post before.
-
Karl - that's the thing I really love about WPF. So many ways to solve the same problem, all of them flexible.
Deja View - the feeling that you've seen this post before.
Pete O'Hanlon wrote:
the thing I really love about WPF. So many ways to solve the same problem
Me too! :cool:
Cheers, Karl
» CodeProject 2008 MVP » Microsoft MVP - Client App Dev My Blog | Mole's Home Page | MVP ProfileJust a grain of sand on the worlds beaches.