New Posts New Posts RSS Feed: Editable Grid Controls
  FAQ FAQ  Forum Search   Calendar   Register Register  Login Login

Editable Grid Controls

 Post Reply Post Reply
Author
Randar View Drop Down
Newbie
Newbie
Avatar

Joined: 13-May-2011
Location: Toronto
Posts: 23
Post Options Post Options   Quote Randar Quote  Post ReplyReply Direct Link To This Post Topic: Editable Grid Controls
    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?



Edited by Randar - 24-May-2011 at 2:59pm
Back to Top
ting View Drop Down
IdeaBlade
IdeaBlade
Avatar

Joined: 27-Mar-2009
Location: San Francisco
Posts: 427
Post Options Post Options   Quote ting Quote  Post ReplyReply Direct Link To This Post 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:

Back to Top
Randar View Drop Down
Newbie
Newbie
Avatar

Joined: 13-May-2011
Location: Toronto
Posts: 23
Post Options Post Options   Quote Randar Quote  Post ReplyReply Direct Link To This Post 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.
Back to Top
ting View Drop Down
IdeaBlade
IdeaBlade
Avatar

Joined: 27-Mar-2009
Location: San Francisco
Posts: 427
Post Options Post Options   Quote ting Quote  Post ReplyReply Direct Link To This Post 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.

Back to Top
 Post Reply Post Reply

Forum Jump Forum Permissions View Drop Down