HighTechTalks DotNet Forums  

Wpf/net 3.5 /VS2008 - Binding to Ado.net dataTable problem

Dotnet Framework microsoft.public.dotnet.framework


Discuss Wpf/net 3.5 /VS2008 - Binding to Ado.net dataTable problem in the Dotnet Framework forum.



Reply
 
Thread Tools Search this Thread Display Modes
  #1  
Old   
Rolf Welskes
 
Posts: n/a

Default Wpf/net 3.5 /VS2008 - Binding to Ado.net dataTable problem - 11-21-2007 , 04:59 PM






Hello,
because there are no managed news group for window presentation foundation
and one
has told me I can use this, here my problem:

Here a litte code with a sample program - simple program which binds to an
ado.net table:

<Window x:Class="Test03.Window1"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:my="clr-namespace:System.Windows.Forms.Integration;assembl y=WindowsFormsIntegration" xmlns:form="clr-namespace:System.Windows.Forms;assembly=System.Win dows.Forms" Title="Window1" Height="414" Width="519"> <Grid Name="grid" Background="LightGray" Height="355" Width="471"> <Grid.Resources> <ObjectDataProvider x:Key="dp" /> </Grid.Resources> <ListBox Margin="12,17,0,0" Name="lbx01" ItemsSource="{BindingSource={StaticResource dp}}" IsSynchronizedWithCurrentItem="True" DisplayMemberPath="Row[0]"HorizontalAlignment="Left" Width="143" Height="78" VerticalAlignment="Top" /> <TextBox Height="23" Margin="183,17,168,0" Name="tx01"VerticalAlignment="Top" Text="{Binding Source={StaticResource dp}, Path=Row[0],UpdateSourceTrigger=PropertyChanged}"/> <TextBox Height="23" Margin="183,48,168,0" Name="tx02"VerticalAlignment="Top" Text="{Binding Source={StaticResource dp}, Path=Row[1],UpdateSourceTrigger=PropertyChanged}"/> <Button Height="23" Margin="183,80,168,0" Name="btnAdd"VerticalAlignment="Top" Click="btnAdd_Click">Add</Button> <my:WindowsFormsHost Margin="12,152,98,82" Name="windowsFormsHost1" > <formataGridView x:Name="dataGridView"/> </my:WindowsFormsHost> </Grid></Window>using System;using System.Data;using System.Collections.Generic;using System.Linq;using System.Text;using System.Windows;using System.Windows.Forms;using System.Windows.Controls;using System.Windows.Data;using System.Windows.Documents;using System.Windows.Input;using System.Windows.Media;using System.Windows.Media.Imaging;using System.Windows.Navigation;using System.Windows.Shapes;namespace Test03{ /// <summary> /// Interaction logic for Window1.xaml /// </summary> public partial class Window1 : Window { DataSet ds; CollectionViewSource cvs; public Window1() { InitializeComponent(); ds = new DataSet(); DataTable table = new DataTable(); DataColumn dcName = new DataColumn("Name"); DataColumn dcFirstName = new DataColumn("FirstName"); table.Columns.Add(dcName); table.Columns.Add(dcFirstName); ds.Tables.Add(table); DataRow row = table.NewRow(); row[0] = "Smith"; row[1] = "John"; table.Rows.Add(row); row = table.NewRow(); row[0] = "Sinclaire"; row[1] = "Jill"; table.Rows.Add(row); DataView dv = new DataView(); dv.Table = table; cvs = new CollectionViewSource(); cvs.Source = dv; ObjectDataProvider dp =(ObjectDataProvider)grid.FindResource("dp"); dp.ObjectInstance = cvs.View; dataGridView.DataSource = dv; } private void btnAdd_Click(object sender, RoutedEventArgs e) { BindingListCollectionView bcv =(BindingListCollectionView)cvs.View; DataView dvx = (DataView)bcv.SourceCollection; DataRowView drv = dvx.AddNew(); drv[0] = "new name"; drv[1] = "new firstName"; } }}Run the program and at the bottom in the DataGridView add a new line forexampleas Name aaa as FirstName bbb now change to the line over the new line to addthe record.You get an FatalExceptionEngineError.Now restart the program.Click the Add Button, a record is added. Now click the Add Button again.Now you get again a FatalExceptionEngineError.So you can not add records in DataGridView (WindowsForms) and you cannot addrecordsdirectly with a button (WPF).Thank you for any help.Rolf Welskes


Reply With Quote
  #2  
Old   
Rolf Welskes
 
Posts: n/a

Default Re: Wpf/net 3.5 /VS2008 - Binding to Ado.net dataTable problem - 11-21-2007 , 08:09 PM






Hello,
as I now see, the code text look awful.
If it is not usable I would send it again.

Thank you.
Rolf Welskes



Reply With Quote
  #3  
Old   
Walter Wang [MSFT]
 
Posts: n/a

Default RE: Wpf/net 3.5 /VS2008 - Binding to Ado.net dataTable problem - 11-22-2007 , 05:15 AM



Hi Rolf,

I've reproduced the issue using following simplified code:

DataTable dt = new DataTable();
dt.Columns.Add("foo");
dt.Rows.Add("bar");
DataView dv = new DataView(dt);
CollectionViewSource cvs = new CollectionViewSource();
cvs.Source = dv;
dv.AddNew();
dv.AddNew();

This is probably related to how DataView internally organize the data:
until you call DataRowView.EndEdit(), the data is not added to the
underlying DataTable. If you try to add the data to the underlying
DataTable directly, then it will be fine. Anyway, I will forward this issue
to WPF team to see if they could give more information.


Regards,
Walter Wang (wawang (AT) online (DOT) microsoft.com, remove 'online.')
Microsoft Online Community Support

==================================================
When responding to posts, please "Reply to Group" via your newsreader so
that others may learn and benefit from your issue.
==================================================

This posting is provided "AS IS" with no warranties, and confers no rights.



Reply With Quote
  #4  
Old   
Rolf Welskes
 
Posts: n/a

Default Re: Wpf/net 3.5 /VS2008 - Binding to Ado.net dataTable problem - 11-23-2007 , 08:53 PM



Hello,
thank you,
but the problem is,
if you use the DataGridView of windows forms (interop with wpf), and enter a
new record
it make also an dv.AddNew().
But here it is not possible to make a work a round because it's the
datagridview-libary-code which makes
the steps.
Thank you
Rolf Welskes

""Walter Wang [MSFT]"" <wawang (AT) online (DOT) microsoft.com> schrieb im Newsbeitrag
news:EJb1uCPLIHA.4200 (AT) TK2MSFTNGHUB02 (DOT) phx.gbl...
Quote:
Hi Rolf,

I've reproduced the issue using following simplified code:

DataTable dt = new DataTable();
dt.Columns.Add("foo");
dt.Rows.Add("bar");
DataView dv = new DataView(dt);
CollectionViewSource cvs = new CollectionViewSource();
cvs.Source = dv;
dv.AddNew();
dv.AddNew();

This is probably related to how DataView internally organize the data:
until you call DataRowView.EndEdit(), the data is not added to the
underlying DataTable. If you try to add the data to the underlying
DataTable directly, then it will be fine. Anyway, I will forward this
issue
to WPF team to see if they could give more information.


Regards,
Walter Wang (wawang (AT) online (DOT) microsoft.com, remove 'online.')
Microsoft Online Community Support

==================================================
When responding to posts, please "Reply to Group" via your newsreader so
that others may learn and benefit from your issue.
==================================================

This posting is provided "AS IS" with no warranties, and confers no
rights.





Reply With Quote
  #5  
Old   
Walter Wang [MSFT]
 
Posts: n/a

Default Re: Wpf/net 3.5 /VS2008 - Binding to Ado.net dataTable problem - 11-25-2007 , 09:53 PM



Hi Rolf,

Thanks for your update.

I'm reported this issue to product group. I'll keep you posted.


Regards,
Walter Wang (wawang (AT) online (DOT) microsoft.com, remove 'online.')
Microsoft Online Community Support

==================================================
When responding to posts, please "Reply to Group" via your newsreader so
that others may learn and benefit from your issue.
==================================================

This posting is provided "AS IS" with no warranties, and confers no rights.


Reply With Quote
  #6  
Old   
Walter Wang [MSFT]
 
Posts: n/a

Default Re: Wpf/net 3.5 /VS2008 - Binding to Ado.net dataTable problem - 11-28-2007 , 01:29 AM



Hi Rolf,

We have tracked down the issue, it's related to ADO.NET DataView will raise
ListChanged(ItemAdded) event twice (one with AddNew, one with EndEdit --
implicitly called by AddNew internally).

Thanks for your great feedback and sorry for the inconvenience caused.


Regards,
Walter Wang (wawang (AT) online (DOT) microsoft.com, remove 'online.')
Microsoft Online Community Support

==================================================
When responding to posts, please "Reply to Group" via your newsreader so
that others may learn and benefit from your issue.
==================================================

This posting is provided "AS IS" with no warranties, and confers no rights.



Reply With Quote
Reply




Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.4
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.