(C#) Recently I am trying to display SQL results from Access MDB to DataGrid upon pressing a button in .xaml. So far I succeed in using ICommand to trigger the SQL and return the results inside a DataTable. I also used PropertyChangedEventHandler to notify the GUI. However, the DataGrid in .xaml does not refresh. (the datagrid appearance remains unchanged)
In the ViewModel, I used below to notify the GUI:
public DataTable TblData
{
get { return _dataTable; }
set
{
_dataTable = value;
RaisePropertyChanged("TblData");
}
}
In the .xaml.cs, I set the DataContext to my ViewModel:
public MainWindow()
{
InitializeComponent();
this.DataContext = _dataViewModel;
}
In the .xaml, I already bind the DataGrid to the DataTable:
<DataGrid Grid.Column="1" Grid.Row="1"
ItemsSource="Binding Path=TblData, Mode=OneWay NotifyOnSourceUpdated=True, UpdateSourceTrigger=PropertyChanged"
AutoGenerateColumns="True" />
Any idea on what I should do to fix? (using MVVM)
Or is there any other better way to do it?
Thanks.