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,
Stefan
3 Answers, 1 is accepted
this
.bindingSourceName.DataSource =
typeof
(Namespace.ClassName);
private
YourCotnextName context;
public
MainApp()
{
this
.InitializeComponent();
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)
{
this
.context.Dispose();
}
Damyan Bogoev
the Telerik team
I have used something like this but new records aren't written back to the db:
private
void btnSave_1_Click(object sender, EventArgs e)
{
vodGroupTypeBindingSource.EndEdit();
vodMediaTypeBindingSource.EndEdit();
vodMediumBindingSource.EndEdit();
vodGroupBindingSource.EndEdit();
vodMediaAccessBindingSource.EndEdit();
vodGroupCustTypeBindingSource.EndEdit();
vodGroupMediaItemBindingSource.EndEdit();
dbContext.SaveChanges();
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.
Thanks,
Craig
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;
this
.context.Add(newCategory);
}
}
}
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,
Petko_I
the Telerik team