Language

Visual Basic

C#

Show All

LanguagesLinqConnectsupport@devart.com

DataBinding in WinForms

This tutorial guides you through the process of creating simple application powered by LinqConnect technology and shows you how to use data binding in the WinForms applications. We use DataGridView component to display the data received from created by us LinqConnect context.

  1. Create a new Windows Forms application in the Microsoft Visual Studio and call it CRM_Demo.
  2. Create a new LinqConnect model. You can read more about that step in the Using Entity Developer section.
  3. Create DataGridView component and two buttons on the form - Refresh (it is used for data retrieving) and Submit (it is used for data updating).

  4. Go to the code editor and define an instance of the DataContext:

    [C#]

    CrmDemoContext.CrmDemoDataContext Context = new CrmDemoContext.CrmDemoDataContext();
    	

    [Visual Basic]

    Dim Context As New CrmDemoContext.CrmDemoDataContext()
    	
  5. Go to the Form Designer and double-click the Refresh button to generate event handler. We assigned the DataSource property of the DataGridView component to the collection named query. Add the following code to it:

    [C#]

    var query = from it in Context.Companies
                select it;
    
    dataGridView1.DataSource = query;
    	

    [Visual Basic]

    Dim query = from it in Context.Companies
                select it
    
    dataGridView1.DataSource = query
    	
  6. Go to the Form Designer and double-click the Submit button to generate event handler. Add the following code to it:

    [C#]

    Context.SubmitChanges();
    	

    [Visual Basic]

    Context.SubmitChanges
    	
  7. Run your application and change value of any cell in our grid and then click the Submit button after that.

    Changes were applied to the database. Just click the Refresh button to see the changes in the data.


 

 


© 2010 - 2014 Devart. All rights reserved.