WPF – Merging GridView Columns

Requirement: We have a ListView with GridView control as View. When we select a particular row, we need to display a textbox merging more than one column of the selected row.

Solution:

<ListView Name=”categoryList”  SelectionMode=”Single” Height=”350″

FontFamily=”Segoe UI” Margin=”49,79,12,0″ IsSynchronizedWithCurrentItem=”True”>

<ListView.Resources>

<ControlTemplate x:Key=”SelectedTemplate” TargetType=”ListViewItem”>

<Border SnapsToDevicePixels=”true”

BorderThickness=”2″

CornerRadius=”5″ x:Name=”border”>

<GridViewRowPresenter>

<GridViewRowPresenter.Columns>

<GridViewColumnCollection>

<GridViewColumn Header=”CategoryId” Width=”100″

DisplayMemberBinding=”{Binding CategoryId}”>

</GridViewColumn>

<GridViewColumn Header=”Title” Width=”300″ >

<GridViewColumn.CellTemplate>

<DataTemplate>

<StackPanel Orientation=”Vertical”>

<TextBox Name=”tt” Width=”288″ />

</StackPanel>

</DataTemplate>

</GridViewColumn.CellTemplate>

</GridViewColumn>

</GridViewColumnCollection>

</GridViewRowPresenter.Columns>

</GridViewRowPresenter>

</Border>

</ControlTemplate>

<Style TargetType=”ListViewItem”>

<Style.Triggers>

<MultiTrigger>

<MultiTrigger.Conditions>

<Condition Property=”IsSelected” Value=”true” />

</MultiTrigger.Conditions>

<Setter Property=”Template” Value=”{StaticResource SelectedTemplate}” />

</MultiTrigger>

</Style.Triggers>

</Style>

</ListView.Resources>

<ListView.View>

<GridView>

<GridViewColumn Header=”CategoryId” Width=”100″

DisplayMemberBinding=”{Binding CategoryId}”>

</GridViewColumn>

<GridViewColumn Header=”Title” Width=”200″ >

<GridViewColumn.CellTemplate>

<DataTemplate>

<StackPanel Orientation=”Vertical”>

<TextBlock Text=”{Binding CategoryTitle}” />

</StackPanel>

</DataTemplate>

</GridViewColumn.CellTemplate>

</GridViewColumn>

<GridViewColumn Header=”Description” Width=”100″

DisplayMemberBinding=”{Binding Description}”></GridViewColumn>

</GridView>

</ListView.View>

</ListView>

Output:

MergeGridView

Advertisements

About ambilykk

I am a Technology Evangelist on Microsoft Technologies. I am carrying the passion on Microsoft technologies specifically on web technologies such as ASP .Net and Ajax. My interests also include Azure and Visual Studio. Technology adoption and learning is my key strength and technology sharing is my passion.
This entry was posted in C#, C# 4.0, WPF and tagged , . Bookmark the permalink.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s