Developer technologies | Windows Presentation Foundation
A part of the .NET Framework that provides a unified programming model for building line-of-business desktop applications on Windows.
This browser is no longer supported.
Upgrade to Microsoft Edge to take advantage of the latest features, security updates, and technical support.
I want that if i book a order of customer of multiple shirts with his name what can i do for multiple rows in datagrid control .like merge cells of excel. customer name in a row while his order of two shirts in two colounms. like below example
Customer Name Order.
Ali Shirt 1
Shirt 2
Hi,
you can use ListBox in DataGridTemplateColumn for Orders. Try following demo:
XAML:
<Window x:Class="Window089"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:local="clr-namespace:WpfApp1.WpfApp089"
mc:Ignorable="d"
Title="Window089" Height="450" Width="800">
<Window.DataContext>
<local:ViewModel/>
</Window.DataContext>
<Grid>
<DataGrid ItemsSource="{Binding View}" AutoGenerateColumns="False">
<DataGrid.Columns>
<DataGridTextColumn Header="Customer" Binding="{Binding Customer}"/>
<DataGridTextColumn Header="Name" Binding="{Binding Name}"/>
<DataGridTemplateColumn Header="Orders">
<DataGridTemplateColumn.CellTemplate>
<DataTemplate>
<ListBox ItemsSource="{Binding Orders}" DisplayMemberPath="OrderName"/>
</DataTemplate>
</DataGridTemplateColumn.CellTemplate>
</DataGridTemplateColumn>
</DataGrid.Columns>
</DataGrid>
</Grid>
</Window>
And classes:
Imports System.Collections.ObjectModel
Imports System.ComponentModel
Namespace WpfApp089
Public Class ViewModel
Public Sub New()
LoadData
End Sub
Private cvs As New CollectionViewSource
Public ReadOnly Property View As ICollectionView
Get
Return cvs.View
End Get
End Property
Private Sub LoadData()
Dim col As New ObservableCollection(Of Data)
For i = 1 To 10
Dim d As New Data With {.Customer = $"Customer {i}", .Name = $"Name {i}"}
For k = 1 To 5
d.Orders.Add(New [Order] With {.OrderName = $"Order {i}-{k}"})
Next
col.Add(d)
Next
cvs.Source = col
End Sub
End Class
Public Class Data
Public Property Customer As String
Public Property Name As String
Public Property Orders As New ObservableCollection(Of Order)
End Class
Public Class Order
Public Property OrderName As String
End Class
End Namespace
Result: