Print Page | Close Window

Editable Grid Controls

Printed From: IdeaBlade
Category: DevForce
Forum Name: DevForce 2010
Forum Discription: For .NET 4.0
URL: http://www.ideablade.com/forum/forum_posts.asp?TID=2712
Printed Date: 29-Jul-2026 at 8:39pm


Topic: Editable Grid Controls
Posted By: Randar
Subject: Editable Grid Controls
Date Posted: 24-May-2011 at 2:35pm
I've got a problem and I'm not sure what the right approach is.  We've got a large number of UltraGrids (from Infragistics) that used to bind to DataTables.  We want to bind them to DevForce instead.  The problem (which applies to DataGrids as well), is that EntityManager->ExecuteQuery returns IEnumerable, which does not support adding items.  So when you click on the grid area to add new items, you get:

Unable to add new row.  Underlying DataSource does not support adding new rows

It would be a considerable amount of effort to move to a different paradigm, so I hope there is a way to get a read/write collection (e.g. IList or IBindingList) from the EntityManager that I could bind to the UltraGrids.

What is the best way to do this?




Replies:
Posted By: ting
Date Posted: 24-May-2011 at 4:35pm
Hi Randar,

Typically, you just add the entities to an ObservableCollection (WPF) or BindingSource (WinForms):

Using the synchronous API:

  var employees = manager.Employees.Execute();
  employees.ForEach(collection.Add);

Using the asynchronous API:

  manager.Employees.ExecuteAsync<Employee>(op => {
    var employees = op.Results;
    employees.ForEach(collection.Add);
  });

To get the add new row functionality in WinForms, you should attach a handler to the BindingSource.AddingNew event and in the event, create the Entity and assign it to the NewObject property of the EventArgs:
http://msdn.microsoft.com/en-us/library/system.windows.forms.bindingsource.addingnew.aspx - http://msdn.microsoft.com/en-us/library/system.windows.forms.bindingsource.addingnew.aspx



Posted By: Randar
Date Posted: 24-May-2011 at 4:48pm
I was afraid you were going to say that.  The problem is that this version of UltraGrid does not have a BindingSource or an AddingNew event.  But, it does have a BeforeRowInsert event (http://help.infragistics.com/Help/NetAdvantage/WinForms/2010.2/CLR2.0/html/Infragistics2.Win.UltraWinGrid.v10.2~Infragistics.Win.UltraWinGrid.UltraGrid~BeforeRowInsert_EV.html), which is functionally equivalent (I hope).  It just means that we'll have to change each one of the controls to implement this method.  A bit of work I had hoped to avoid, but at least it lays out the concept on how to handle inserting records with DF.

Thanks for the insight.


Posted By: ting
Date Posted: 24-May-2011 at 5:30pm
You should be able to set the UltraGrid.DataSource property to a .NET BindingSource (which satisfies the editable collection requirement).

Infragistics certainly supports the IBindingList interface, which is implemented on the BindingSource, but I don't know if it uses the AddingNew event. You might have to implement BeforeRowInsert as you pointed out.

I'm not seeing any interface on the DataTable that does this either. They probably coded specifically for the DataTable and call NewRow on it. You'll probably need to implement BeforeRowInsert for any non-DataTable source.




Print Page | Close Window