0

H I use SQL CE and LINQ. I bind property typeof Table on ItemSource of Datagrid control from WPF Toolkit.

Something like this.

    public Table<TestNick>  MySource
    {
        get { return _tab; }
        set
        {
            _tab = value;
            NotifyPropertyChanged("MySource");

        }
    }


    <Controls:DataGrid Name="Dg" 
                       ItemsSource="{Binding Path=MySource, Mode=OneWay, UpdateSourceTrigger=PropertyChanged}"
                       Grid.Row="0"/>

I retrieve data from DB with LINQ:

        const string connStr = @"Spiri_SQL_CE_DB.sdf";
        _dc = new Spiri_SQL_CE_DB(connStr);
        MySource = _dc.TestNick;

If I add a breakpoint on last line I see all values from tables TestNick, but it doesn’t load this data in DataGrid.

What is bad?

EDITED:

I check the ItemSource of DataGrid control in code behind, the item source is correct but I see in DataGrid (view) "old data".

So binding must be correct, problem is that DataGrid control doesn’t refresh data.

3
  • Just guessing, is there a BindingExpression error in the output window?
    – DHN
    Jan 26, 2011 at 14:24
  • Binding is Ok, ItemSource property of DataGrid consist good data, but in view I see old data.
    – user572844
    Jan 26, 2011 at 15:10
  • You can remove UpdateSourceTrigger=PropertyChanged as that is not needed Jan 26, 2011 at 15:14

1 Answer 1

0
  • Make sure datagrid autogeneratecolumns is true
  • While running check the output window if there are any binding issues
  • Another trick is to put a button on the view and write a code behind function on click of that button to debug whats the datagrid itemsource, if its empty try to invoke viewModel/Model's getDatagridData function and then see if it loads, in case it loads that means your NotifyPropertyChanged is not yet functional
3
  • Oki, problem is that ItemSource of DataGrid is correct but in view I don’t see actual data. I see old data.
    – user572844
    Jan 26, 2011 at 15:06
  • If you add the button on view (just for debugging purpose) and write a code behind to invoke the getData function, if you see new data after that. That means your NotifyPropertyChange is not working. You can also put a break point inside NotifyPropertyChange. Also are you using ObservableCollection?
    – ns12345
    Jan 26, 2011 at 15:12
  • ObservableCollection doesn't matter as the OP is replacing the reference. Jan 26, 2011 at 15:13

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.