in

vbCity Blogs

New (temp) place for vbCity Blogs

Mike McIntyre's .NET Journal

July 2009 - Posts

  • Silverlight 2 Blog Post 4 - Change of Plans

    I've decided to stop blogging about Silverlight 2 and start blogging about Silverlight 3.

    I think it makes more sense to blog about Silverlight 3 now. Since I started posting about getting started with Silverlight 2, Silverlight 3 has been released.

    It also seems to make more sense to blog about Silverlight techniques I'm using in real world projects rather than blog about how to get started.  There are many excellent tutorials, blogs, and books about learning SIlverlight basics and more being published everyday. I see far less information about using Silverlight for real applications - something I can blog about from experience.

    Next stop - Silverlight 3.

     

     

  • Binding Source For DataGridView From Linq To Sql Query

    LINQ to SQL translates LINQ queries to SQL for execution on a database. The results are strongly typed IEnumerable. Because these objects are ordinary common language runtime (CLR) objects, ordinary object data binding can be used to display the results. On the other hand, sorting and change operations (inserts, updates, and deletes) require additional steps.

    For example, to provide a DataSource for a DataGridView that can be sorted using the DataGridView's built in sorting capabilities, you can not assisign a LINQ TO SQL query directly to the DataGridView's DataSource. 

    Instead, assign a LINQ TO SQL query to a BindingSource and then assign the BindingSource to a DataGridView.

    Visual Basic Example

     

        Friend Shared Function CreditCardTypesList(ByVal activeFilter As Boolean, ByVal titleFilter As String) As BindingSource
            Dim newBindingSource As New BindingSource()
            newBindingSource.DataSource = _
             From e In DB.VYDal.CreditCardTypes _
             Where e.Active = activeFilter And SqlMethods.Like(e.Title, titleFilter & "%") _
             Order By e.Title _
             Select e
            Return newBindingSource
        End Function

     Bind the Binding Source to a DataGridView:

     

        Private Sub LoadGridView()
            entityGridView.DataSource = DB.CreditCardTypesList(True, titleFilterTextBox.Text)
        End Sub

    C# Example

            internal static BindingSource CreditCardTypesList(bool activeFilter, string titleFilter)
            {
     
                BindingSource bs = new BindingSource();
                bs.DataSource = from e in DB.VYDal.CreditCardTypes
                                where e.Active == activeFilter & SqlMethods.Like(e.Title, titleFilter + "%")
                                orderby e.Title
                                select e;
                return bs;
            }

     Bind the BindingSource to a DataGridView:

            private void LoadGridView()
            {
                entityGridView.DataSource = DB.CreditCardTypesList(true, titleFilterTextBox.Text);
            }

     

     

  • Deborah Kurata's Blogging Now

     Long time Visual Basic and .Net expert Deborah Kurata started blogging!

    Deborahs Developer Mindscape

Copyright 1998-2009 vbCity.com LLC
Powered by Community Server (Non-Commercial Edition), by Telligent Systems