Home Forums WPF controls Xceed DataGrid for WPF Problem with Grid binding

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

    Hello I have to following scenario. I have a grid showing some information depending on some date range. When change the date range I want to change the data in the grid.

    <Page.Resources>

    <xcdg:DataGridCollectionViewSource x:Key=”cvsTimesheet”
    Source=”{Binding Path=Timesheet}”>
    <xcdg:DataGridCollectionViewSource.GroupDescriptions>
    <xcdg:DataGridGroupDescription PropertyName=”date_log”/>
    </xcdg:DataGridCollectionViewSource.GroupDescriptions>
    </xcdg:DataGridCollectionViewSource>

    </Page.Resources>

    <xcdg:DataGridControl X:Name=”gridTimesheet” AutoCreateColumns=”False” ValidationMode=”CellEndingEdit” ItemScrollingBehavior=”Immediate”
    ItemsSource=”{Binding Source={StaticResource cvsTimesheet}}”>
    <xcdg:DataGridControl.Columns>
    <xcdg:Column FieldName=”timelog_id” Visible=”False”/>
    <xcdg:Column FieldName=”project_id” Title=”Project ID” Width=”60″ />
    <xcdg:Column FieldName=”project_name” Title=”Project Name” Width=”340″ />
    <xcdg:Column FieldName=”date_log” Title=”Date” Width=”100″ ReadOnly=”True” />
    <xcdg:Column FieldName=”time_length” Title=”Time Worked (HH:MM)”
    CellContentTemplate=”{StaticResource TimeLengthCellContentTemplate}” />
    </xcdg:DataGridControl.Columns>
    </xcdg:DataGridControl>

    In my .CS file I have the following:

    public DataTable Timesheet
    {
    get
    {
    DataSet dsTimesheet = /*Get data depending on the selected dates */
    return dsTimesheet.Tables[0];
    }
    }

    I have set in the constructor
    this.DataContext = this

    My page inherits INotifyPropertyChanged.

    When I initially load the page everything is ok. But when I click on a button to change the date range:

    private void btnPreviousWeek_Click(object sender, RoutedEventArgs e)
    {
    OnPropertyChanged(new PropertyChangedEventArgs(“Timesheet”));
    }

    the grid is displayed, columns, rows everything is correct but there is no data inside – the cells are empty. There is data but it’s not displayed in the cells. May be it sounds a little bit complicated but I will be very happy if someone helps me.
    Thank you in advance.

    Imported from legacy forums. Posted by Martin (had 4576 views)

    Xceed Support
    Member
    Post count: 5658

    This is most likely because the DataColumns in the Table gets reset when you change (re-fill) the data source.

    To workaround this, simply place a simple DisplayMemberBinding in the column definitions (e.g. {Binding timelog_id} )

    Imported from legacy forums. Posted by Marcus [Xceed] (had 321 views)

    User (Old forums)
    Member
    Post count: 23064

    So you suggest to add somethink like this for each column

    <xcdg:Column
    FieldName=”project_id”
    DisplayMemberBinding=”{Binding Path=project_id}”
    Title=”Project ID”
    Width=”60″
    ReadOnly=”True” />

    Or maybe I should make DataTemplate for all of the columns?

    Imported from legacy forums. Posted by Martin (had 383 views)

    User (Old forums)
    Member
    Post count: 23064

    I don’t what’s wrong now, but after adding DisplayMemberBinding the grid’s showing nothing. Only the structure is correct, but no data inside. Should it be done like the way I said in the prevoius post? Is there any specific thing, depending on binding to DataTable?

    Imported from legacy forums. Posted by Martin (had 419 views)

    Xceed Support
    Member
    Post count: 5658

    Yes, the binding should be done as you indicated in your post.

    I see nothing wrong with the code you have. It could be either that the problem is really obvious but can`t see it ( post holiday weakness ), or that its a particular quirk that evades us.

    You could try re-enabling the AutoCreateColumns property, so you can see what is happening with the columns.

    Imported from legacy forums. Posted by Marcus [Xceed] (had 300 views)

    User (Old forums)
    Member
    Post count: 23064

    Well, after several attempts to fix this I finally gave up. I made my own object depending on the columns (each column – different object property) and I bind the columns to the properties and now everything works fine. May be there is smth I miss in binding the grid to a DataTable.

    Imported from legacy forums. Posted by Martin (had 424 views)

    User (Old forums)
    Member
    Post count: 23064

    FYI.

    I’m having the same problem when binding to a DataView object. The data does not show up in the columns once you rebind the grid. The data triggers work correctly once our data source is updated. I think the data is present, but it’s not showing up for some reason. We have no solution for the problem at this point. I’m hoping we can get some support for this issue and then I’ll repost.

    Imported from legacy forums. Posted by Paul (had 5539 views)

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