no new record displayed after submitchanges()

Jul 31, 2009 at 4:57 AM

I'm not seeing the new record in the datagrid after calling submitchanges(). I've verified that the record is added to the table.

Is there some common mistake that is made to get this to work?

 

Thanks,

 

Bill

Jul 31, 2009 at 3:36 PM
On 7/30/2009 11:57 PM, wpmccormick wrote:
>
>
> From: wpmccormick
>
> I'm not seeing the new record in the datagrid after calling
> submitchanges(). I've verified that the record is added to the table.
>
> Is there some common mistake that is made to get this to work?


I made a short little test application, just to prove that this doesn't work
under the most simple of scenarios:

<Window x:Class="DataGridTest.Main"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:toolkit="http://schemas.microsoft.com/wpf/2008/toolkit"
Title="DataGridTest" Height="600" Width="800">
<Grid>
<DockPanel>
<toolkit:DataGrid Name="Test"
DockPanel.Dock="Top"
AutoGenerateColumns="True"
CanUserAddRows="False">
</toolkit:DataGrid>
<StackPanel DockPanel.Dock="Bottom" Orientation="Vertical"
Margin="20">
<Button HorizontalAlignment="Right" Width="80"
Click="Button_Click">Refresh</Button>
</StackPanel>
</DockPanel>
</Grid>
</Window>


namespace DataGridTest
{
/// <summary>
/// Interaction logic for Main.xaml
/// </summary>
public partial class Main : Window
{
private SQLScrpDbDataContext Db = new SQLScrpDbDataContext();

public Main() {
InitializeComponent();
Db.DeferredLoadingEnabled = false;
Test.ItemsSource = Db.Materials;
}

private void Button_Click(object sender, RoutedEventArgs e) {
Db.Refresh(RefreshMode.KeepChanges, Db.Materials);
Test.Items.Refresh();
}
}
}

Note: SQLScrpDbDataContext is a LinqToSql Datacontext.
Jul 31, 2009 at 9:51 PM
On 7/31/2009 10:37 AM, iamwpmccormick wrote:
>
>
> From: iamwpmccormick
>
> On 7/30/2009 11:57 PM, wpmccormick wrote:
> >
> >
> > From: wpmccormick
> >
> > I'm not seeing the new record in the datagrid after calling
> > submitchanges(). I've verified that the record is added to the table.
> >
> > Is there some common mistake that is made to get this to work?
>
>
> I made a short little test application, just to prove that this doesn't
> work
> under the most simple of scenarios:
>
> <Window x:Class="DataGridTest.Main"
> xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
> xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
> xmlns:toolkit="http://schemas.microsoft.com/wpf/2008/toolkit"
> Title="DataGridTest" Height="600" Width="800">
> <Grid>
> <DockPanel>
> <toolkit:DataGrid Name="Test"
> DockPanel.Dock="Top"
> AutoGenerateColumns="True"
> CanUserAddRows="False">
> </toolkit:DataGrid>
> <StackPanel DockPanel.Dock="Bottom" Orientation="Vertical"
> Margin="20">
> <Button HorizontalAlignment="Right" Width="80"
> Click="Button_Click">Refresh</Button>
> </StackPanel>
> </DockPanel>
> </Grid>
> </Window>
>
>
> namespace DataGridTest
> {
> /// <summary>
> /// Interaction logic for Main.xaml
> /// </summary>
> public partial class Main : Window
> {
> private SQLScrpDbDataContext Db = new SQLScrpDbDataContext();
>
> public Main() {
> InitializeComponent();
> Db.DeferredLoadingEnabled = false;
> Test.ItemsSource = Db.Materials;
> }
>
> private void Button_Click(object sender, RoutedEventArgs e) {
> Db.Refresh(RefreshMode.KeepChanges, Db.Materials);
> Test.Items.Refresh();
> }
> }
> }
>
> Note: SQLScrpDbDataContext is a LinqToSql Datacontext.
>

Here's what I did to solve this:


namespace DataGridTest
{
/// <summary>
/// Interaction logic for Main.xaml
/// </summary>
public partial class Main : Window
{
private static SQLScrpDbDataContext Db = new SQLScrpDbDataContext();

public static IEnumerable<Material> Materials {
get {
//return from m in Db.Materials select m;
return from m in Db.Materials orderby m.MtlId select m;
}
}

public Main() {
InitializeComponent();


Test.ItemsSource = Materials;
}

private void Button_Click(object sender, RoutedEventArgs e) {
Db.Refresh(RefreshMode.KeepChanges, Db.Materials);

Test.ItemsSource = Materials;
}
}
}