• Beth Massi - Sharing the goodness

    ASP.NET Dynamic Data Tutorials

    • 6 Comments

    Bill Burrows has released more video tutorials! This time he focuses on the ASP.NET Dynamic Data feature that is available in Visual Studio 2008 SP1.  If you need to build a quick web site against a database then you should definitely check this framework out.

    Also check out the Web Development section of the Visual Basic Learning page for more VB ASP.NET videos.

    Enjoy!

  • Beth Massi - Sharing the goodness

    Data Sources and Data Binding in WPF Talk in Redmond

    • 6 Comments

    On Monday night I spoke at my first .NET users group here on the Microsoft Campus. It was the Visual Basic .NET Developers Association meeting that's here in Building 40/41 Steptoe room behind the cafeteria. It's held every last Monday of the month so if you are in the Seattle area then you should check it out, they've got a great lineup of Microsoft speakers from the VB team presenting.

    I have to say I was slightly more nervous than the usual user group meeting because the audience was about half Microsoft employees and there were 4 MVPs in the room including the organizer Robert Green. Bill Vaughn, Rocky Lhokta, and Ted Neward were also there. I was also being filmed so there was this big video camera in the back of the room -- made me feel a little bit like a press release ;-). But by the time I got to my second slide I calmed down and fell into my normal presentation rhythm. And having such high caliber audience made for a lot of great discussions -- really engaging with a lot of participation.

    I started the talk with basics of data binding to a variety of data sources and then we moved to more to data access discussions and n-tier architecture issues. It was similar to the talk I did at Bay.NET in SF last month but I focused this time completely on WPF and didn't show any Winforms at all. This allowed us to have more time for architecture discussions and I think it worked out well. It was a fun meeting and nothing blew up so that was nice too ;-).

    I think the coolest part was when I got a question form a gentleman in the crowd and I asked him what kind of applications he was building and he said "CodePlex". He was a developer on the CodePlex team -- cool! I told him to say HI to Sara. At the end I also had a Silverlight question that I didn't know the answer to but it turned out that Beatriz from the WPF team was in the audience ready to help me out. At the end both she and Rocky told me that my presentation was well done and accurate. It was great to hear from the experts that I did well and didn't **** anything up. :-)

    I've attached the presentation and code samples.

    Enjoy!

  • Beth Massi - Sharing the goodness

    Silverlight 2 How Do I Videos

    • 2 Comments

    If you're interested in learning about Silverlight, check out the How Do I videos on Silverlight 2, which include managed code examples in both Visual Basic and C#. All you need to get started building Silverlight applications is here on the Get Started page of www.silverlight.net. There are also a lot of great articles, tutorials and samples so check them out. Also check out Tim Heuer's blog for excellent information on Silverlight.

    If you like what you see, bookmark it. ;-)

    Enjoy!

  • Beth Massi - Sharing the goodness

    Enabling Remote SQL Express 2008 Network Connections on Vista

    • 56 Comments

    Today I spent way too long trying to enable remote network connections on my SQL 2008 Express database running on my Vista development machine so I thought I'd post the steps here. Please note that these settings may NOT be appropriate for your production environments. I'm a developer ;-), hence this is what I did to get the development environment working. If you need to set up production environments I'd read the SQL Server Books online.

    Normally when developing code I always use the local SQL Express instance on my box and the default install takes care of everything so local connections via Visual Studio work fine. But what I was doing today was trying to connect a VPC to SQL 2008 Express on my host development machine in order to test some apps, simulating a network. When installing SQL 2005 or 2008 Express it locks out remote access to be on the safe side. Here's the basic steps you need to do to get it working:

    1. Open up the SQL Server Configuration Manager. Programs / Microsoft SQL Server 2008 / Configuration Tools / SQL Server Configuration Manager.

    2. Expand the SQL Server Network Configuration node and select the Protocols for SQLEXPRESS

    3. Enable TCP/IP by right-clicking and selecting Enable, then OK.

    4. Click on the SQL Server Services node and in the right panel right-click SQL Server (EXPRESS) and select restart to restart the service.

    5. Right-click on the SQL Server Browser and select start to start the browser service if it isn't started already. This will allow you to access the SQL Express instance by the computer name.

    6. Open up SQL Server Management Studio as Administrator. (If you don't have SSMS installed, get it here)

    7. In the Object Explorer under the Security node, add a new user for the account that will be connecting by right-clicking and selecting "New User". This opens the Login Properties page. If you're on a domain then use Windows Authentication. For my VPC scenario it wasn't connected to a domain so I added a SQL Server login and password. (To enable SQL logins you need to first right-click on the SQL Express instance at the top, select Properties and under Security select "SQL Server and Windows Authentication mode".)

    8. Select User Mapping on the Login Properties and check off the database you want to connect to. If you're just testing then you can select db_owner in the role membership to grant all access to the database, including altering the schema. Please note that this is not secure but it works for development and testing.

    If you want to be secure you can go and specifically grant permissions under the Security node for the specific database back up in the Object Explorer. But if you're on a domain then I would recommend creating a least privileged Windows Security Group on your domain and adding that to a SQL Server Role that you can configure explicit permissions on (i.e. GRANT EXECUTE on your CRUD stored procs and GRANT SELECT on tables, don't let DELETE, INSERT and UPDATE directly). Then you can just use normal Windows security to add users on the domain to the group. This also lets you use integrated security in the connection strings which is much more secure.

    9. Configure the Firewall. This is the step that I forgot and was banging my head on the wall 4-EV-R! Open up Windows Firewall and select Change Settings, select the Exceptions Tab and click Add Program. You'll need to select the SQLservr.exe in Program Files\Microsoft SQL Server\MSSQL10.SQLEXPRESS\MSSQL\Binn\ and the SQLBrowser.exe in Program Files\Microsoft SQL Server\90\Shared\. Then select Properties for each of them and select the "Change Scope" button. Then select the proper scope. For development and testing you could specify the remote computer's IP address or widen it to your network subnet. I recommend not allowing Internet users. ;-)

    10. Configure the connection string. Now back in Visual Studio you can configure your connection string settings in your Project Settings (app.config). If you used Windows Authentication then it's really easy:

    Data Source=SERVERNAME\sqlexpress;Initial Catalog=MyDatabase;Integrated Security=True

    If you used a SQL Login then you need to supply a less secure connection string with the username and password:

    Data Source=SERVERNAME\sqlexpress;Initial Catalog=MyDatabase;User ID=username;Password=password

    I hope that works for you, it did for me. If you're still having trouble please see these troubleshooting tips in the library or ask a question on the SQL Server forums. I'm by no means an expert in SQL Server configuration or networks.

    Enjoy!

  • Beth Massi - Sharing the goodness

    Editing Tabular Data in WPF - Building a WPF Grid

    • 19 Comments

    In my last post on WPF I showed how you could use a Winforms DataGridView on a WPF form in order to edit data in a tabular style. Today I'll show you how you can customize the WPF ListView in order to edit data without having to use any Winforms controls at all.

    WPF gives us the ultimate flexibility when it comes to designing our UI, it just takes learning what XAML we need to get the job done. The WPF ListView control is easily customizable using templates in a GridView mode where we can specify exactly what controls should display for each column of data for each of our rows, along with being able to style the column headers, so that we can build our very own editable grid. (I'd recommend going over the ListView How-To topics in the library especially this one for a good overview on common styles and techniques).

    Getting Data on Our Form

    Let's take a simple example. Create a new WPF project and drop a ListView from the toolbox onto Window1. Unlike the last example that used a Winforms DataGridView, we can't use the designer in Visual Studio 2008 to automatically data bind our data to WPF controls and set up our object instances, so we'll need to set that up manually like I've shown in this video. I'm using Visual Studio 2008 SP1 so for this example I'm going create an ADO.NET Entity Data Model against my database. I'm not going to go into the details of the Entity Framework here, I'll save that for a later post. And this is just one of many ways to access data -- remember that you can use any data source that makes sense for your application in WPF, even typed DataSets or LINQ to SQL classes.

    For this example we'll just work with a standard Customer table so just right-click on the project, select ADO.NET Entity Data Model, point it at the database, and then select the Customer table. This sets up a simple model that maps directly to our database table in similar fashion as LINQ to SQL. Next we'll fill the data in our Window.Loaded event handler using a LINQ to Entities query that selects just the customers in California. Then we set those results to the Window's DataContext. We'll also want to get at the BindingListCollectionView, so that we can control the position and add and remove rows to the grid easily (which is a new SP1 feature of this class like I explained in this post). So our code that sets up our data should look something like this:

    Class Window1
    
        Private MyData As New MyDataEntities
        Private CustomerView As BindingListCollectionView
    
        Private Sub Window1_Loaded() Handles MyBase.Loaded
    
            Dim customersInCali = From c In MyData.Customer _
                                  Where c.State = "CA" _
                                  Order By c.LastName
    
            Me.DataContext = customersInCali
            Me.CustomerView = CType(CollectionViewSource.GetDefaultView(Me.DataContext),  _
                                    BindingListCollectionView)
        End Sub

    Now that we have the code to load our data we can focus on the XAML we need to create an editable grid.

    ListView Simple Data Binding

    So let's just get this thing displaying the list of our customers. Because we set the Window's DataContext to the list of customers we can use a special syntax to tell the ListView to pick up that same DataContext of the Window. Note that if we had a parent/child association on our objects (i.e. each of our Customer objects had a list called "Orders" for instance) we could specify the property name of the child list here. Also we'll want this ListView to pay attention to the position of the BindingListCollectionView so we need to set the IsSynchronizedWithCurrentItem property to True as well. Finally, we can specify a simple property name to display in the list via the DisplayMemberPath property, here I'm just using the LastName field.

    <ListView Name="ListView1"  
              ItemsSource="{Binding Path=''}"
              IsSynchronizedWithCurrentItem="True"
              DisplayMemberPath="LastName"/>

    So now our ListView now looks like a simple Listbox, simply displaying the LastName columns in a display-only list. To make it look more like a grid we need to add a GridView to the ListView's View property. The GridView lends itself well to a grid-style table that lets you define multiple columns for the items in our data source which will display in multiple rows. Multiple GridViewColumn objects can be added to the GridView which can either automatically size to their content or we can specify a width. So instead of specifying the DisplayMemberPath property above, we're going to use a GridView, add a couple GridViewColumns, and then set up the field names we want to bind to. Let's add columns for LastName, FirstName and State columns:

    <ListView Name="ListView1"  
              ItemsSource="{Binding Path=''}"
              IsSynchronizedWithCurrentItem="True">
        <ListView.View>
            <GridView>
                <GridViewColumn DisplayMemberBinding="{Binding Path=LastName}" 
                                Header="Last Name" Width="100"/>
                <GridViewColumn DisplayMemberBinding="{Binding Path=FirstName}" 
                                Header="First Name" Width="100"/>
                <GridViewColumn DisplayMemberBinding="{Binding Path=State}" 
                                Header="State" Width="50"/>
            </GridView>
        </ListView.View>
    </ListView>

    Editing the Data

    Now we're starting to look more like a data grid. However, by default the GridView cannot directly update the data that it displays. For this we need to add what's called a DataTemplate to the GridViewColumn's CellTemplate property. This allows us to configure exactly what the controls should be used for each column. For this example we can use TextBoxes in our DataTemplates like so:

    <ListView Name="ListView1"  
              ItemsSource="{Binding Path=''}"
              IsSynchronizedWithCurrentItem="True">
        <ListView.View>
            <GridView>
               <GridViewColumn Header="Last Name" Width="100">
                    <GridViewColumn.CellTemplate>
                        <DataTemplate>
                            <TextBox Text="{Binding Path=LastName}" />
                        </DataTemplate>
                    </GridViewColumn.CellTemplate>
               </GridViewColumn>
               <GridViewColumn Header="First Name" Width="100">
                    <GridViewColumn.CellTemplate>
                        <DataTemplate>
                            <TextBox Text="{Binding Path=FirstName}" />
                        </DataTemplate>
                    </GridViewColumn.CellTemplate>
               </GridViewColumn>
               <GridViewColumn Header="State" Width="50">
                    <GridViewColumn.CellTemplate>
                        <DataTemplate>
                            <TextBox Text="{Binding Path=State}" />
                        </DataTemplate>
                    </GridViewColumn.CellTemplate>
               </GridViewColumn>
            </GridView>
        </ListView.View>
    </ListView>

    However you'll notice that this doesn't quite line up our TextBoxes how we'd like them because they will only take up the length of the data inside. Instead, we want them to take up the same width as the column. For this we need to set the Margin on each individual TextBox and then add a property setter to the ListView's ItemContainerStyle in order to set the same HorizontalContentAlignment style for each of the rows to "Stretch".

    <ListView Name="ListView1"  
              ItemsSource="{Binding Path=''}"
              IsSynchronizedWithCurrentItem="True">
        <ListView.ItemContainerStyle>
            <Style TargetType="ListViewItem">
                <Setter Property="HorizontalContentAlignment" Value="Stretch" />
            </Style>
        </ListView.ItemContainerStyle>
        <ListView.View>
            <GridView>
               <GridViewColumn Header="Last Name" Width="100">
                    <GridViewColumn.CellTemplate>
                        <DataTemplate>
                            <TextBox Text="{Binding Path=LastName}" 
                                     Margin="-6,0,-6,0" />
                        </DataTemplate>
                    </GridViewColumn.CellTemplate>
               </GridViewColumn>
                <GridViewColumn Header="First Name" Width="100">
                    <GridViewColumn.CellTemplate>
                        <DataTemplate>
                            <TextBox Text="{Binding Path=FirstName}" 
                                     Margin="-6,0,-6,0" />
                        </DataTemplate>
                    </GridViewColumn.CellTemplate>
                </GridViewColumn>
                <GridViewColumn Header="State" Width="50">
                    <GridViewColumn.CellTemplate>
                        <DataTemplate>
                            <TextBox Text="{Binding Path=State}" 
                                     Margin="-6,0,-6,0" />
                        </DataTemplate>
                    </GridViewColumn.CellTemplate>
                </GridViewColumn>
            </GridView>
        </ListView.View>
    </ListView>

    Now this is starting to look more like a data grid. And you'll notice now we can edit the data:

    Of course you can play with the styles and style templates to get the exact effects you want but as you can see it's pretty straight forward to hook up our data binding and edit the rows using DataTemplates.

    Adding, Deleting and Saving

    In order to Add and Delete items we can use the BindingListCollectionView to work with our data source, in this case a simple list of customers. Using the BindingListCollectionView the adding and deleting of items of data in the list is the same no matter what the data source. However the mechanism for saving your data will vary. In my case I'm using Entity Framework so I can tell the ObjectContext to SaveChanges. So I'll add three buttons onto the Window for Add, Delete and Save. Then in the Click Event handlers we can write some code:

    Private Sub btnNew_Click() Handles btnNew.Click
        Dim customer = CType(Me.CustomerView.AddNew, Customer)
        customer.LastName = "<new>"
        Me.CustomerView.CommitNew()
    End Sub
    
    Private Sub btnDelete_Click() Handles btnDelete.Click
        If Me.CustomerView.CurrentPosition > -1 Then
            Me.CustomerView.RemoveAt(Me.CustomerView.CurrentPosition)
        End If
    End Sub
    
    Private Sub btnSave_Click() Handles btnSave.Click
        Try
            MyData.SaveChanges()
            MsgBox("Saved customers successfully.")
        Catch ex As Exception
            MsgBox(ex.ToString)
        End Try
    End Sub

    Run the application, make some changes and then click Save and you should see your data save properly. However you should notice that if you try to delete a row, it seems to be deleting the wrong one sometimes. This is because that even though we specified the IsSynchronizedWithCurrentItem property on the ListView, if we select a TextBox directly in the rows, the selection doesn't actually move. It only moves correctly if we click outside of the TextBoxes on the row. To fix this we can add a simple Event Handler to the ListBoxItem.GotFocus event that will force the selected item to be that of the ListBoxItem's DataContext. You can do this easily by adding an EventSetter in the ListView.ItemContainerStyle template:

    <ListView.ItemContainerStyle>
         <Style TargetType="ListViewItem">
            <Setter Property="HorizontalContentAlignment" Value="Stretch" />
            <EventSetter Event="GotFocus" Handler="Item_GotFocus"/>
         </Style>
    </ListView.ItemContainerStyle>

    Then in the code we can handle the event like so:

    Private Sub Item_GotFocus(ByVal sender As System.Object, _
                              ByVal e As System.Windows.RoutedEventArgs)
    
        Dim item = CType(sender, ListViewItem)
        Me.ListView1.SelectedItem = item.DataContext
    End Sub

    There's other handlers we could add in this manner for controlling other aspects of the grid. Take a look at the ListView Overview for more information on what you can do. I've uploaded this sample onto Code Gallery along with the last one that used a Winforms DataGridView: http://code.msdn.microsoft.com/wpftabulardata

    I hope this gives you a good start into understanding how to bind data into an editable tabular-style user interface. It's pretty simple to get something basic together as you can see but if you have extremely complex needs or don't want to spend the time on building one yourself, I urge you to take a look at third-party WPF grids on the market as well as what the WPF team is building on CodePlex.

    Enjoy!

  • Beth Massi - Sharing the goodness

    Social Bookmarking V1 Launched (I'm in the How-To Video!)

    • 1 Comments

    Chris posted this week about the new version of our social bookmarking platform and he's got a couple cool videos on his blog on how to use the features. He uses me as one of his examples so I thought it was pretty cool ;-). I better get back to bookmarking things!

    You can look at my bookmarks here. We also have a social feed on the VB Dev Center Community page so try it out, tag things "visual basic" and you'll see them show up on the Dev Center.

    Enjoy!

  • Beth Massi - Sharing the goodness

    What's New in Visual Studio 2008 SP1 - Client and Data Features

    • 6 Comments

    Last night I spoke at East Bay.NET UG on some of the new features in Visual Studio Service Pack 1 focusing on client and data. I did a whirlwind tour of new SQL 2008 data types and Sync Services enhancements, ADO.NET Entity Framework, ADO.NET Data Services, WPF performance and data enhancements, Client Profile Deployment, VSTO Add-In Host Controls and Smart Tags, and VSTO deployment and end-user install troubleshooting improvements. There is just so much packed into SP1 that next month we'll be doing a talk on all things web including ASP.NET Dynamic Data and MVC.

    The talk went really well and it was a lot of fun. I've uploaded the presentation and demos onto Code Gallery here: http://code.msdn.microsoft.com/whatsnewvs2008sp1

    Enjoy!

  • Beth Massi - Sharing the goodness

    Community Article: Using Windows Communication Foundation with Windows Workflow Foundation, Part 2

    • 2 Comments

    Maurice is on fire with his latest series of Workflow articles on the Visual Basic Developer center. In this second of two articles on WCF and Workflow , Maurice de Beijer shows us how to use the ReceiveActivity, which allows you to publish a workflow as a WCF service -- very handy. If you missed them, here's the rest:

    Workflow Foundation 101

    The Power of Custom Workflow Activities (Part 1)

    The Power of Custom Workflow Activities (Part 2)

    Using Windows Communication Foundation with Windows Workflow Foundation – Part 1

    Using Windows Communication Foundation with Windows Workflow Foundation – Part 2

    Thanks for contributing, Maurice!

    And check out the Learn section of the Visual Basic Developer Center for more Visual Basic Learning on Workflow.

    Enjoy!

  • Beth Massi - Sharing the goodness

    Channel9 Interview: Meet the VS "Development Experience" Team

    • 4 Comments

    I just posted another Channel9 interview. This time I meet with the team that brings us the "experience" of coding in Visual Studio, also sometimes referred to as the VS IDE Team. I ask them how their design process works, what the top requested features are for the code editors, how they work with the language teams as well as what their favorite and hardest features are to build and test.


    Meet the Visual Studio Managed Languages Development Experience Team

    Enjoy!

  • Beth Massi - Sharing the goodness

    For Sale: 2003 ESX Stage 4 Subaru WRX

    • 18 Comments
    Option Personal On

    Yes it's time to sell the Subaru. (I know I rarely write purely personal posts on my blog, but heck even Sara has done it before.) I bought a new car last week -- an Infiniti G37 6MT -- and I LOVE it. I know it's not as fast or as practical as my Subaru but it's got black leather seats and it's shiny and new... oh and it has dual exhaust and it sounds so good growling down the street. I'll make it much faster later -- it took me a couple years to build my Subaru the way I like it, so give me some time. ;-)

    So here's my baby that I'm selling. If any of you know me personally I am a total car enthusiast and I took care of this car like no other (I have all the records and dyno reports). If I could afford all the insurance on both cars I would keep her. But I figure I can find a good home for her with someone who is as into cars as I am. I've put so much money into this work of art I know I'll never get it back. But I'm not into cars for money, I'm into going really really fast -- and this one does that very well. ;-)

    FOR SALE - (Northern California)
    2003 Easy Street ESX Stage 4 WRX

    Race Inspired Daily Driver

    3 8

    6 5 9 10

    1 2 12 11

    Do you want a reliable daily driver that's a functional wagon and lives up to your performance expectations? This car is race-inspired and was built by one of the most prestigious Subaru racing shops in L.A. Enter the Easy Street ESX Stage 4 WRX Wagon.

    Dyno Tested: 239.6hp at the wheels @6250 RPM 221.8ft-lbs torque @4500 RPM

    Performance Features: Easy Street Stage 4 performance package, IHI VF-34 Turbo, 3" exhaust & downpipe, Injen polished cold air intake w/ extra filter, Helix Flex up-pipe, large MRT top mounted intercooler, STI 300cc Injectors and fuel system, NGK Iridium plugs, bigger STI hood scoop, TEIN Superstreet suspension w/ EDFC (cockpit dampener controller), GFB Blow-off valve, Cusco front strut bar, Blitz turbo timer, Autometer cobalt series boost gauge, 18" Rotas w/ Sumitomo 225/40ZR18 tires, Tinted windows, Alpine amplifier + sub whoofer, Cobra radar detector, Yakima bike roof rack, Garmin navigation system, 1 yr old clutch, + more! Over $25K in modifications!

    Standard Factory Features: Midnight Black Pearl w/ black cloth interior, rear spoiler, 4-cylinder turbo, 5-speed manual transmission, driver & passenger airbags, alarm, anti-lock brakes, bucket seats, 6 disk CD changer, cassette radio, cruise control, fog lights, power locks, power steering, power windows, premium sound, rear window defroster, rear window wiper

    This car is in great condition with only 64,500 miles. I am a car enthusiast that never misses a service or synthetic oil change. Tuned for street driving but can be retuned easily to race, she has a clean title and has never had any mechanical problems. I’m the original owner and I have all service records and the original ESX brochure. The 60K-mile service is DONE, all service is up to date. Price Includes all original stock parts.

    Asking $19,000

    Contact me if you are interested in a test drive!
Page 1 of 2 (13 items) 12