Beth's Chinese blog
I just posted an interview with Kris Makey, a Developer on the Office Client team. Here he shows us a couple new features of Office projects in Visual Studio 2008 SP1. First he demonstrates a new error logging feature that will log any end-user install errors to the Event Log making it much easier to tell what went wrong. He also shows us how you can place Winforms controls directly on document surfaces.
For more information on Office Development with Visual Studio visit the developer portal http://msdn.com/vsto and the team blog http://blogs.msdn.com/vsto/.
Enjoy!
Bill Burrows has released a new set of videos on the ASP .NET MVC Framework - Preview 4 Update which provides an overview of the MVC pattern as well as shows you how to perform adds and updates against a database. If you missed them, you should first check out his Intro to MVC videos and LINQ to SQL tutorials.
Bill is a professor and Visual Basic MVP who is providing these completely free of charge to the community. Thanks Bill!
I just posted another Channel 9 interview on SP1. This time, Yang Xiao, a tester on the VB IDE team is back demonstrating new improvements to the "Go To Definition", "Find All References" and Rename capabilities in the editor when flipping between code and XAML in Visual Studio 2008 Service Pack 1.
New Editor Features in Visual Studio 2008 SP1
Last night I spoke to SF Bay.NET user's group on Data Binding in Winforms and WPF, focusing on Line-of-Business (LOB) application scenarios. I showed how you can use the same data sources with Winforms and WPF, walking through binding scenarios with DataSets, custom object collections and some LINQ to SQL classes. I showed the common data binding interfaces and demonstrated the main objects involved in data binding in both Windows client technologies. I also showed the side effects on data binding when using LINQ over these data sources.
I then tried to squeeze in a 10 minute discussion and demonstration of n-tier scenarios and how to handle some of the main issues you run into depending on your choice of data source and data access technology. I also plugged my "forms over data" videos. Of course I could have gone another hour! I ALWAYS have too much material. I should just do a day training class or something.
I think the talk turned out really well (I snuck a look at the evals and looks like people got a lot from the talk). Next time I'll cut down on the Winforms demos and focus on WPF and more n-tier, switching to Winforms only as a necessary comparison once in a while. However, I was impressed with the number of people that had not done Winforms data programming and there were a lot of note takers and questions when I went through the Winforms demos as well. Maybe I'll break it into two sessions and add them to my SV code camp talks.
I promised the crowd I would post the deck and the code I showed. Special thanks to Brian Noyes and his awesome "Data Binding with Windows Forms 2.0" book that I bought a couple years ago and still refer to often. One of the code demos I showed was based on some of the code from this awesome book. I have a signed copy ;-) The only thing I wish was that there was a WPF update, hint hint hint ;-)
Download the presentation here.
One of the things I was really missing from WPF when I started to dig into data binding was feature consistency between the BindingListCollectionView and the Winforms BindingSource I had grown to love. The BindingListCollectionView provides the navigation, currency, filtering and sorting on the bound collection of data (or DataTable) just like the BindingSource in Winforms.
However transacted adding and removing of items to the collections was not supported. You'll notice in my WPF Forms over Data videos when I go to add or remove a row of my data I have to access the DataTable directly. This isn't really a problem when working with DataTables because they can do their own transacted editing (along with change tracking). However this is usually a necessary feature in order to work well with custom business collections implementing typical binding interfaces.
SP1 Adds New Properties/Methods to WPF's BindingListCollectionView
With the release of Visual Studio/.NET FX SP1 they've enhanced the BindingListCollectionView to include new properties and methods: CanAddNew property, CanCancelEdit property, CanRemove property, CurrentAddItem property, CurrentEditItem property, IsAddingNew property, IsEditingItem property, ItemProperties property, NewItemPlaceholderPosition property, AddNew method, CancelEdit method, CancelNew method, CommitEdit method, CommitlNew method, EditItem method, Remove method, RemoveAt method.
One thing that I want to point out here that's different is in Winforms we used to call EndEdit on the BindingSource to push all transacted changes whether they were edits or adds to the bound data source (i.e. the DataTable or your collection). In WPF there's a separate call for CommitEdit and CommitNew and you have to make sure you don't call CommitEdit if you are in the middle of an add that calls AddNew, instead you have to call CommitNew. I'm not sure why they separated this. When using DataSets I always commit the changes pretty much right away (after filling default values for instance) and rely on the DataSet's change tracking using Accept/RejectChanges.
Adding and Removing Data with the New AddNew and Remove Methods
When we want to add a new row of data to a DataTable we can now call AddNew directly on the BindingListCollectionView. For instance..
Private OrderData As New OrdersDataSet Private OrdersViewSource As BindingListCollectionView
Sub New() ' This call is required by the Windows Form Designer. InitializeComponent() ' Add any initialization after the InitializeComponent() call. Me.LoadData() Me.DataContext = Me.OrderData.Orders Me.OrdersViewSource = CollectionViewSource.GetDefaultView(Me.DataContext) End Sub
Private Sub AddNewOrder() '--- Old Code --- 'Add a new row to the collection 'Dim order = Me.OrderData.Orders.NewOrdersRow 'Me.OrderData.Orders.AddOrdersRow(order) 'Up to us to update the position 'Me.OrdersViewSource.MoveCurrentToLast() '--- New Code --- 'Add a new row to the collection Me.OrdersViewSource.AddNew() 'Push changes into the DataTable Me.OrdersViewSource.CommitNew() End Sub
Above I'm handling all the validation and setting of default values via the DataSet partial classes so the AddNewOrder() method would remain unchanged if we were working against our own business object collections. This is what I came accustomed to in Winforms, you can easily swap out your data sources without messing with the data binding code. Keep in mind though that if you call CommitNew and the DataRow is invalid, you'll get an error when it's pushed into the DataSet -- so make sure to handle the TableNewRow event on the DataTable partial class and fill in valid default values.
Removing the current row is also very straightforward:
Private Sub RemoveOrder() If Me.OrdersViewSource.CurrentPosition > -1 Then '--- Old Code --- 'Dim order As OrdersDataSet.OrdersRow 'order = CType(CType(Me.OrdersViewSource.CurrentItem, DataRowView).Row, OrdersDataSet.OrdersRow) 'order.Delete() '--- New Code --- Me.OrdersViewSource.Remove(Me.OrdersViewSource.CurrentItem) End If End Sub
Working with Master-Detail Forms in WPF
These are good improvements but the BindingSource in Winforms is still easier to work with at the moment IMHO because the BindingSource is a visual component that handles the underlying CurrencyManager goo. One thing that's a pain is when you are working with master-detail binding scenarios in WPF. You need to obtain a reference to the details' BindingListCollectionView every time the detail view changes (this would be the ItemSource on a ListBox or ListView). If you've got the binding set up correctly in the XAML then the detail view changes automatically when the parent's position changes. However, if you want to AddNew into the child then you need to obtain a reference in code every time because the view is dynamic. Winforms BindingSources handle this scenario better.
Even though we need to obtain a reference every time, it's fairly straightforward:
Private Sub AddNewDetail() If Me.OrdersViewSource.CurrentPosition > -1 Then '--- Old Code --- 'Dim order As OrdersDataSet.OrdersRow 'order = CType(CType(Me.OrdersViewSource.CurrentItem, DataRowView).Row, _ ' OrdersDataSet.OrdersRow) 'Dim detail = Me.OrderData.OrderDetail.NewOrderDetailRow 'detail.OrderID = order.OrderID 'Me.OrderData.OrderDetail.AddOrderDetailRow(detail) '--- New Code --- Dim detailView As BindingListCollectionView = _ CollectionViewSource.GetDefaultView(Me.lstDetails.ItemsSource) detailView.AddNew() 'Note that the related OrderID is set for us automatically just like Winforms detailView.CommitNew() End If End Sub Private Sub RemoveDetail() If Me.OrdersViewSource.CurrentPosition > -1 Then Dim detailView As BindingListCollectionView = _ CollectionViewSource.GetDefaultView(Me.lstDetails.ItemsSource) If detailView.CurrentPosition > -1 Then '--- Old Code --- 'Dim detail As OrdersDataSet.OrderDetailRow 'detail = CType(CType(Me.OrderDetailsViewSource.CurrentItem, DataRowView).Row, _ ' OrdersDataSet.OrderDetailRow) 'detail.Delete() '--- New Code --- detailView.Remove(detailView.CurrentItem) End If End If End Sub
By using the new AddNew and Remove methods it also seems to solve some issues I was seeing when working with LINQ to SQL generated child collections (EntitySets) as well so it's best to start taking advantage of these new methods. In a future blog post I'll take the LINQ to SQL N-Tier application we did a while back and slap a WPF Front end on it.
I'm probably not going to update the videos I've already done, but going forward I'll be using these new methods and properties where appropriate so go download SP1 ;-)
I just posted an interview on Channel 9 with Yang Xiao, a tester on the VB IDE. In this interview Yang shows us the new XML Schema Explorer in Visual Studio 2008 Service Pack 1. This new window is invoked when you right-click on an XML literal element or namespace and select "Show in XML Schema Explorer" in Visual Basic programs. It's a nice way to visually display the structure of your schema sets which makes you even more productive when working with XML in Visual Basic.
XML Schema Explorer in Visual Studio 2008 SP1
Harry Miller, programming writer for office development, has been producing office video tips on the VSTO team blog and they've been featuring on the Office Development portal on MSDN.
I have to say the last couple videos are hilarious and extremely creative. I especially like this one with the techno-vertigo trip into the documentation library. My favorite quote from that one "VSTO, tell me where to go", LOL! Really well done, I'm laughing and learning at the same time. Keep them up, Harry!
One of my good friends Sara Ford finally finished her Visual Studio Tips book, based on her super popular tip-of-the-day blog series she started over a year ago when I first started Microsoft.
The amazing thing about the book is that she's dedicating 100% of the profits to create a scholarship at the Mississippi Gulf Coast Community College for anyone living in her hometown of Waveland, Mississippi, which was destroyed during Hurricane Katrina. Microsoft matches any employee's donations to charities so this is a really big help for students in Waveland.
I'm so happy Sara finally finished it! I'm so proud of her. Tonight I'm buying the beer. ;-)
Go Sara, go!
I just posted a new Channel 9 interview with Milind Lele, a PM on the VS Pro Tools team. In this interview Milind shows us the improvements made to the tooling in Visual Studio SP1 for occasionally connected clients as well as the new data type support for SQL Server 2008.
Using SQL 2008 built-in change tracking, you don't need to make modifications to your table schemas like you have to do with SQL 2005. Additionally he shows off a "smarter" DataSet designer where you can have tables coming from server and client data stores all contained within one model making maintenance easier.
A Bay Area local Silverlight expert, Cal Schrotenboer, created a cool slider puzzle from a picture of me. Check it out! I have not been able to solve it, but I admit I stink at these things... not enough patience or time in the day ;-)
Also check out some other beautiful slider puzzles from Cal and a few cool deep zooms.
Thanks, Cal!