Data-Binding a WPF DataGrid Control to a System.Data.DataTable Object?

InitializeComponent() will instantiate your markup, including the binding. At that point DTUsers is still null so nothing is displayed. Then, you change DTUsers but there's no way for the binding (and therefore the grid) to know that you did it - and so it does not do anything.

Up vote 1 down vote favorite share g+ share fb share tw.

I've been suffering over this for several days now. Even when the binding and the query both work correctly, and there is observable data in the table - nothing shows up in the data grid. My XAML code resembles this: My C# code-behind resembles this: (DAO is my Data Access Object) public partial class Window1 : Window { public dao DAO = new dao (ConnectionString) ; public System.Data.

DataTable DTUsers { get; set; } public Window1() { InitializeComponent(); if (DAO! = null) DTUsers = DAO. Query( @"SELECT * FROM users" ); // Returns a DataTable object containing user records.

// I have confirmed that this returns my data correctly. } } I've checked the output, and there are no binding errors. Why will this compile and run, but won't display any data?

(If you don't know where the DataGrid control is, the WPF Toolkit is available here. Install it, add a reference to WPFToolkit. Dll which will show up in the "Add Reference" dialog under ".

NET", and provide the XML namespace declaration in my XAML above to use the WPF DataGrid control. ) c# .net wpf data-binding xaml link|improve this question edited Jul 10 '09 at 21:03 asked Jul 10 '09 at 20:28Giffyguy1,08721355 94% accept rate.

InitializeComponent() will instantiate your markup, including the binding. At that point DTUsers is still null, so nothing is displayed. Then, you change DTUsers, but there's no way for the binding (and therefore the grid) to know that you did it - and so it does not do anything.

You should either make DTUsers a dependency property, or implement INotifyPropertyChanged on your class, and raise PropertyChanged event after you change the value of the property.

That makes perfect sense! Thanks a ton! – Giffyguy Jul 10 '09 at 23:08 Hmm --- I moved InitializeComponent() to the very bottom of the constructor, and now at least the DataGrid is able to populate itself with the proper columns and column headers ... but it still shows no data records ... Any other ideas?

I'll up-vote you again if you want to give another answer. – Giffyguy Jul 10 '09 at 23:37 Oh, I had accidentally left my query commented out ... by bad. It works perfectly now, thanks to your answer!

– Giffyguy Jul 10 '09 at 23:42.

I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.

Related Questions