Home Forums WPF controls Xceed DataGrid for WPF Columns and their order

Viewing 5 posts - 1 through 5 (of 5 total)
  • Author
    Posts
  • User (Old forums)
    Member
    Post count: 23064
    #25296 |

    Hello,
    I am sorry if the following question has already been brought up but I couldn’t find anything like it while browsing.

    I am evaluating whether Xceed DataGrid is fitting the projects needs. Currently it is depending on one issue. Is it possible to dynamically determine which columns in wich order get shown in the datagrid? With the datastructure itself staying the same of course.

    To clarify in an example:
    The grid displays some Data with the colums Song, Artist and Album
    A specific user always wants the order Album, Song and Artist .
    Is it possible to define this order e.g. in an Xml file and and set the columns dynamically on each start of the application?
    Is it possible to use:

    <xcdg:Column FieldName=”SongName”
    IsMainColumn=”True”
    Width=”200″
    Title=”Song”/>
    with Fieldname being bound to a dependency property?

    I hope you understand my question and any hint would be useful. Thank you in advance.

    Imported from legacy forums. Posted by Door (had 3242 views)

    User (Old forums)
    Member
    Post count: 23064

    Hi, All column definitions have a property called VisiblePosition which means you can add columns in a set order, but actually reorder them by using the VisiblePosition property.

    This means that you should be able to achieve your requirements using this grid

    Imported from legacy forums. Posted by Derek (had 455 views)

    User (Old forums)
    Member
    Post count: 23064

    Thanks for your reply.
    I’ve found a way to do it, but not a very “nice” way. If I set the the property in the page’s constructor, it works:
    public MainPage()
    {

    InitializeComponent();

    this.grid.Columns[0].VisiblePosition = 7;
    this.grid.Columns[1].VisiblePosition = 6;
    this.grid.Columns[2].VisiblePosition = 5;
    this.grid.Columns[3].VisiblePosition = 4;
    this.grid.Columns[4].VisiblePosition = 3;
    this.grid.Columns[5].VisiblePosition = 2;
    this.grid.Columns[6].VisiblePosition = 1;
    this.grid.Columns[7].VisiblePosition = 0;

    this.UpdateGridCellEditorDisplayConditions();
    this.UpdateGridEditTriggers();
    }

    however, I would like to use an XmlDataProvider for this, but it’s not working. Here is the code:

    XML File Positions.xml:

    <?xml version=”1.0″ encoding=”utf-8″ ?>
    <GridPositions>
    <Included>7</Included>
    <Songname>6</Songname>
    <Artist>5</Artist>
    <LastPlayed>4</LastPlayed>
    <Category>3</Category>
    <Country>2</Country>
    <Rating>1</Rating>
    <SongID>0</SongID>
    </GridPositions>

    XAML code:
    XmlDataProvider:
    <XmlDataProvider x:Key=”cPositions” Source=”Positions.xml” />

    Grid:

    <xcdg:DataGridControl x:Name=”grid”
    ItemsSource=”{Binding Source={StaticResource cvsSongs}}”
    ItemScrollingBehavior=”Immediate”
    DataContext=”{DynamicResource cPositions}”>
    <xcdg:DataGridControl.View>
    <xcdg:TableView Theme=”{DynamicResource defaultTheme}”/>
    </xcdg:DataGridControl.View>

    <xcdg:DataGridControl.Columns>
    <xcdg:Column FieldName=”Included”
    Width=”80″
    GroupValueTemplate=”{StaticResource includedGroupValueTemplate}”
    VisiblePosition=”{Binding XPath=/GridPositions/Included}”/>
    <xcdg:Column FieldName=”SongName”
    IsMainColumn=”True”
    Width=”200″
    Title=”Song”
    VisiblePosition=”{Binding XPath=/GridPositions/SongName}” />
    <xcdg:Column FieldName=”Artist”
    Width=”150″
    VisiblePosition=”{Binding XPath=/GridPositions/Artist}” />

    <xcdg:Column FieldName=”LastPlayed”
    Title=”Last Played”
    VisiblePosition=”{Binding XPath=/GridPositions/LastPlayed}” />
    <xcdg:Column FieldName=”Category”
    Width=”100″
    CellEditor=”{StaticResource categoryEditor}”
    CellContentTemplate=”{StaticResource categoryCellDataTemplate}”
    VisiblePosition=”{Binding XPath=/GridPositions/Category}”/>
    <xcdg:Column FieldName=”Country”
    VisiblePosition=”{Binding XPath=/GridPositions/Country}”/>
    <xcdg:Column FieldName=”Rating”
    VisiblePosition=”{Binding XPath=/GridPositions/Rating}” />
    <!– Invisible columns –>
    <xcdg:Column FieldName=”SongID”
    Visible=”False”
    VisiblePosition=”{Binding XPath=/GridPositions/SongID}” />
    </xcdg:DataGridControl.Columns>
    </xcdg:DataGridControl>

    Anyone have an idea why thats not working?

    Imported from legacy forums. Posted by Door (had 435 views)

    User (Old forums)
    Member
    Post count: 23064

    I found that you cannot set the VisiblePosition higher than the columns that had been defined at that point in time. Hence I had to create all teh columns and then go through and set their VisiblePositions.

    Sorry that I cannot help you to find a suitable solution for this but maybe someone else can elaborate on this one as I am sure it is a common problem.

    Imported from legacy forums. Posted by Derek (had 3993 views)

    User (Old forums)
    Member
    Post count: 23064

    Argh. I just hit the same issue while trying to bind VisiblePosition to properties of my ViewModel. Is there another workaround for this? Seems like it would be impossible to do databinding to VisiblePosition if it can’t be (temporarily, at least) set to a value higher than the current number of columns…

    Imported from legacy forums. Posted by Wayne (had 429 views)

Viewing 5 posts - 1 through 5 (of 5 total)
  • You must be logged in to reply to this topic.