Simple WinForms example ?

4 posts, 0 answers
  1. Stefan
    Stefan avatar
    1 posts
    Member since:
    Mar 2008

    Posted 16 Aug 2010 Link to this post

    I am struggling with OA to get a simple WinForms application running.

    What I have done is to add a new domain model and add some tables from my db and build the solution.
    In the data sources tab I have created new data sources on basis of the objects created by OA and
    dragged them on the form where they have created the standard controls.

    When I run the application, all controls remain empty. What am I missing ?

    Is the OA approach not that straightforward ?

    Sadly I did not find any simple Winforms example to learn from.

    Thanks in advance,
  2. Damyan Bogoev
    Damyan Bogoev avatar
    581 posts

    Posted 17 Aug 2010 Link to this post

    Hi Stefan,

    The controls do not show any data because their binding source controls are bound in the following way:

    this.bindingSourceName.DataSource = typeof(Namespace.ClassName);

    You should bind the BindingSource controls using the following approach in order to load the necessary data:

    private YourCotnextName context;
    public MainApp()
        this.context = new YourCotnextName();
        this.bindingSourceName.DataSource = this.context.DataEndPoint.ToList();
        this.FormClosing += new FormClosingEventHandler(MainApp_FormClosing);
    private void MainApp_FormClosing(object sender, FormClosingEventArgs e)

    You could find this getting started tutorial useful, it demonstrates how to integrate a WinForms application with Telerik OpenAccess ORM, as well as this code library example.
    Hope that helps.

    Damyan Bogoev
    the Telerik team
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
  3. DevCraft banner
  4. Craig Parks
    Craig Parks avatar
    1 posts
    Member since:
    Jul 2012

    Posted 25 Aug 2010 Link to this post

    Wondering if you have a simple winforms example like this that demonstrates how to write changes in radgridview back to a bindingsource that uses the domain ORM?

    I have used something like this but new records aren't written back to the db:



    void btnSave_1_Click(object sender, EventArgs e)



    dbContext.Refresh(RefreshMode.OverwriteChangesFromStore, dbContext.VodGroupCustTypes);
    dbContext.Refresh(RefreshMode.OverwriteChangesFromStore, dbContext.VodGroupMediaItems);
    dbContext.Refresh(RefreshMode.OverwriteChangesFromStore, dbContext.VodGroups);
    dbContext.Refresh(RefreshMode.OverwriteChangesFromStore, dbContext.VodGroupTypes);
    dbContext.Refresh(RefreshMode.OverwriteChangesFromStore, dbContext.VodMedia);
    dbContext.Refresh(RefreshMode.OverwriteChangesFromStore, dbContext.VodMediaAccesses);
    dbContext.Refresh(RefreshMode.OverwriteChangesFromStore, dbContext.VodMediaTypes);
    vodMediaTypeBindingSource.DataSource = dbContext.VodMediaTypes.ToList();
    vodGroupTypeBindingSource.DataSource = dbContext.VodGroupTypes.ToList();
    vodMediumBindingSource.DataSource = dbContext.VodMedia.ToList();
    vodGroupBindingSource.DataSource = dbContext.VodGroups.ToList();
    vodMediaAccessBindingSource.DataSource = dbContext.VodMediaAccesses.ToList();
    vodGroupCustTypeBindingSource.DataSource = dbContext.VodGroupCustTypes.ToList();
    vodGroupMediaItemBindingSource.DataSource = dbContext.VodGroupMediaItems.ToList();

    The various radgridview .datasources are set to one of the BindingSources at runtime.


  5. Petko_I
    Petko_I avatar
    184 posts

    Posted 30 Aug 2010 Link to this post

    I have attached an example which shows how to handle the three main operations with the new domain context – update, insert and delete. I have demonstrated how to make modifications which are propagated to the database layer when the Save Changes button is clicked.
    The binding source collection is not directly connected to the domain context because the ToList() method creates a new collection separated from the dbContext.VodMediaTypes IQueryable.  
    vodMediaTypeBindingSource.DataSource = dbContext.VodMediaTypes.ToList();

    The persistent objects that have been obtained from the context can be updated with the same context. The problem comes when you add an item to (or delete an item from) the binding source. As the list is not connected in any way to the context, you need to invoke the Add method with the new item as a parameter. To do this you can handle the ListChanged event of the binding source and check if the type of the operation is addition.  

    private void View_DataSourceCollectionChanged(object sender, System.ComponentModel.ListChangedEventArgs e)
        if (e.ListChangedType == ListChangedType.ItemAdded)
            BindingSource source = sender as BindingSource;
            if (e.NewIndex >= 0 &&
                e.NewIndex < source.List.Count)
                Category newCategory = source.List[e.NewIndex] as Category;

    The same event can be used to check if an item is deleted but there is not a direct way to obtain a reference to it. In the example I have subscribed to the RowsChanging event of the grid in order to show how to cancel an unintended deletion.

    I would like to highlight that with the old scope approach you can use an ObjectView which can greatly simplify your application logic. The downside is you cannot work with the visual designer (if you resort to the classic wizards).

    If you need further assistance, do not hesitate to contact us back.

    Sincerely yours,
    the Telerik team
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
Back to Top