I'm trying to use GridControl
from DevExpress but I can't do the same thing I usually do in ListView
with a GridView
View
.
I did both aproach. Using DisplayMemberBinding
and CellTemplate
. Both show nothing. Code below (I removed some columns):
<dxg:GridControl ItemsSource="{Binding}" Name="gridControl1">
<dxg:GridControl.Columns>
<dxg:GridColumn Header="Teste" DisplayMemberBinding="{Binding DataNascimento}"/>
<dxg:GridColumn Header="Nome">
<dxg:GridColumn.CellTemplate>
<DataTemplate>
<TextBlock Text="{Binding Nome}"/>
</DataTemplate>
</dxg:GridColumn.CellTemplate>
</dxg:GridColumn>
</dxg:GridControl.Columns>
<dxg:GridControl.View>
<dxg:TableView Name="tableView1" AutoWidth="True" />
</dxg:GridControl.View>
</dxg:GridControl>
It is shown like this image:
You can see my columns but no data. I bound 3 items and it shows 3 rows. The data itself is bound but looks like the template was not shown.
I tried the same aproach of this question but not work for me.
My class have INotifyPropertyChanged
and I used an ObservableCollection<T>
before bindind to the GridControl
.
The only way it works is if I remove almost all code and change the AutoPopulateColumns
to True
. But in some cases I want a custom format and cannot achieve with this option.
Edit1: I did this in Design mode and works:
<dxg:GridColumn FieldName="DataNascimento" Name="gridColumn3">
<dxg:GridColumn.EditSettings>
<dxe:TextEditSettings DisplayFormat="{}{0:dd/MM/yyyy HH:mm:ss}" />
</dxg:GridColumn.EditSettings>
</dxg:GridColumn>
Edit2:
Tried the same aproach @blindmeis
suggests with grid and it works like I spected:
<DataGrid AutoGenerateColumns="False" Grid.Row="2" ItemsSource="{Binding}">
<DataGrid.Columns>
<DataGridTextColumn Binding="{Binding DataNascimento}" Header="Nascimento" />
<DataGridTextColumn Binding="{Binding Nome}" Header="Header" />
<DataGridTemplateColumn Header="Teste">
<DataGridTemplateColumn.CellTemplate>
<DataTemplate>
<TextBox Text="{Binding Nome}"/>
</DataTemplate>
</DataGridTemplateColumn.CellTemplate>
</DataGridTemplateColumn>
</DataGrid.Columns>
</DataGrid>
Looks like this aproach works in both ListView
and DataGrid
. Unfortunately GridControl
behaves different.
Using <dxg:GridColumn.EditSettings>
is the correct way?