Can anyone point me to a very simple example(C#4.0) of a WPF Datagrid thats bound to a SQL table. I’d really like the simplist example possible. I want to be able to add, edit and delete rows. Thanks.
Share
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Seems like an old thread, but hopefully this will still be useful. If you can get your data into an ObservableCollection, then most of the hard stuff will be done for you. From there you can just do something like this:
or, if you want to do it in XAML, you can do something like this:
and then make sure you have an object called ocItems in your code.
By using an ObservableCollection, you get add and delete updates automatically for you so you don’t have to tell the DataGrid to update. By using twoway binding, you get any editing that has been done taken care of for you as well. You can customize the look of the DataGrid with the DataGridColumns items, but I’ll let you look that up yourself.