0

I have bound a collection from my database to a DevX GridControl. By default, it is shows all columns. How can I modify my Xaml code to strictly show the columns that I specify?

Here is the Xaml code:

    <dxg:GridControl x:Name="lst1" AutoGenerateColumns="AddNew" ItemsSource="{Binding ListaImpianti}" ColumnsSource="{Binding c}" 
                     EnableSmartColumnsGeneration="True" HorizontalAlignment="Left" Margin="93,131,0,0" VerticalAlignment="Top" Width="346"
                     FilterCriteria="{Binding FilterCriteria, ElementName=searchControl}" Height="479" >
        <dxg:GridControl.Columns>
            <dxg:GridColumn x:Name="CODICE" Binding="{Binding CODICE}" FieldName="CODICE"/>
            <dxg:GridColumn x:Name="NOME" Binding="{Binding NOME}" FieldName="NOME"/>
        </dxg:GridControl.Columns>
        <dxg:GridControl.View>
            <dxg:TableView AllowPerPixelScrolling="True"  ShowTotalSummary="True" AllowEditing="False" ShowGroupPanel="False" />
        </dxg:GridControl.View>
    </dxg:GridControl>

ListaImpianti is the query result from the ViewModel. It contains numerous fields and I would like to only show the fields NOME and CODICE.

RLH
  • 15,230
  • 22
  • 98
  • 182
Piero Alberto
  • 3,823
  • 6
  • 56
  • 108
  • 1
    I don't know if this the way to set the columns if you only require 2 to be displayed, have you tried creating the columns manually and then assign what you want to them, avoiding autogeneration? – XAMlMAX Sep 15 '14 at 08:05
  • I have edited the code. I have inserted the gridcontrol.colums, but the final results is the same... did you mean this with your comment? – Piero Alberto Sep 15 '14 at 08:19
  • 1
    you need to remove `AutoGenerateColumns="AddNew"` and it should work. – XAMlMAX Sep 15 '14 at 08:21
  • No worries, it was a quick solution so I don't think there is a need for an answer. – XAMlMAX Sep 15 '14 at 08:28

2 Answers2

1

SOLUTION: remove AutoGenerateColumns="AddNew".

Piero Alberto
  • 3,823
  • 6
  • 56
  • 108
0

I ran into this problem, however, I was using a GridControl from within a ControlTemplate that was embedded within a LookUpEdit control. I found it rather frustrating since no option within the AutoGenerateColumns had any effect. After a bit of further digging, I found that the LookUpEdit control has a property called AutoPopulateColumns which overrides this value. The property is a boolean and setting it to False will allow you to manually define your own columns.

RLH
  • 15,230
  • 22
  • 98
  • 182