0

I have an xceed:DataGridControl with bounded ItemsSource. Currently I'm trying to set my in/visible columns and the title/headertext for each visible column. Preferably I would like to bind a property in my ViewModel, to set the in/visible columns and theirs titles. But I find no way I could do it. Does anyone know a solution to this problem?

<xceed:DataGridControl
    x:Name="dataGridControl"
    SelectedItem="{Binding SelectedTextItem, UpdateSourceTrigger=PropertyChanged, Mode=TwoWay}"
    ItemsSource="{Binding ItemsSourceData, UpdateSourceTrigger=PropertyChanged, Mode=TwoWay}" >
</xceed:DataGridControl>
peter70
  • 1,053
  • 16
  • 31

2 Answers2

0

Yes indeed I had to deal with xceed's controls few months ago.

DataGridControl allows you to generate columns automantically. That is also its default behavior.

In order to have your own columns you will have to disable the property AutoCreateColumns and futhermore you will have to set few columns on the property DataGridControl.Columns.

There you will be able to bind Visible property of the Column.

Thanks to Peter for providing this code:

<xceed:DataGridControl ItemsSource="{Binding TextSet}" > 
  <xceed:DataGridControl.Columns>
    <xceed:Column FieldName="ColumnId" Title="{Binding DatagridTitle[ColumnId], Mode=OneWay}" Visible="True" />
  </xceed:DataGridControl.Columns>
</xceed:DataGridControl>
dev hedgehog
  • 8,698
  • 3
  • 28
  • 55
  • Thx, sorry when I´m a litle bit groggy, but the Columns property of xceed DataGridControl is readonly. Furthermore I think the idea with the binding in my ViewModel is not so good, but Columns are part of UI and the ViewModel should not implement any parts of the UI. So I think now the codebehind of my view is a well place for properties like ColumnCollection – peter70 Nov 09 '13 at 11:16
  • Net Dev added my question. Take a look at the link he provided. – dev hedgehog Nov 09 '13 at 12:23
  • In case, that other developers will searching a solution for this problem, here I would like to present a solution ` ` – peter70 Nov 11 '13 at 09:22
0

I also met similar issue.

You can use the Visible property, then do following:

<xcdg:ColumnFieldName="ColumnId" Title="ColumnId" 
Visible="{Binding RelativeSource={RelativeSource Mode=FindAncestor,AncestorType={x:Type typeOfAncestor}}, Path=DataGridControl.DataContext.BooleanSourceProperty}"/>

For example, if the typeOfAncestor is xcdg:MergedColumn and BooleanSourceProperty is IsVisble, then the code should be:

<xcdg:ColumnFieldName="ColumnId" Title="ColumnId"
Visible="{Binding RelativeSource={RelativeSource Mode=FindAncestor,AncestorType={x:Type xcdg:MergedColumn}}, Path=DataGridControl.DataContext.IsVisible}"/>

Then the issue can be solved.

Bravo Yeung
  • 8,654
  • 5
  • 38
  • 45