Somewhat OT: Add New button on Infragistics UltraGrid

Somewhat OT: Add New button on Infragistics UltraGrid

Old forum URL: forums.lhotka.net/forums/t/1334.aspx


ajj3085 posted on Tuesday, September 26, 2006

Hi,

I have a UltraGrid which is bound to one of my business collections.  I can't allow new rows to be added like you would a DataGridView, that is by typing in the 'blank' row at the bottom to auto create the row because I need to create the object in the collection via a factory method, which takes parameters.

So I show the Add new button at the button of the grid.  What I'd like to do is when the user clicks this button, I can show a dialog where the user enters the necessary information.

If they cancel, no row should be added.  If they enter all the info in the dialog, the row should be added.

I can't find which events are appropriate to enable this behavior; the grid always tries to find a default constructor on the BO which is contained in the list. 

Any help would be appreciated.
Thanks

Michael Hildner replied on Tuesday, September 26, 2006

Hi Andy,

Not sure if this will help or not. I've found the add new button to be limiting, so I just don't use it. I just put my own button below the grid, then you can code whatever you want, such as calling .AddNew().

Mike

ajj3085 replied on Tuesday, September 26, 2006

Mike,

I was afraid of that.  I guess that's the approach I'll take, unless someone else knows how to make it more useful.

Andy

Michael Hildner replied on Tuesday, September 26, 2006

Andy,

I'm curious - what's the advantage of the add new button over a regular button? I want to see what I'm missing out on.

Just a couple thoughts. I guess you could copy the data into something that did work with the add new button (dataset / datatable?)- I haven't tried it, so I don't know what you'd lose out on.

I'm assuming you're getting that "Unable to add a row: Row insertion not supported by 
this data source" message - that was happening to me. I tried to handle the grid's BeforeRowInsert event, but that I guess that happens after that message. You could handle the grid's Error event, check for the error, do your thing and then cancel the event. I tried that and it worked. Seems ugly though.

Mike

ajj3085 replied on Wednesday, September 27, 2006

Mike,

Apparently there isn't. Smile [:)]

It was mainly just because the button was part of the grid, it looked nicer because its next to another grid.  So putting normal buttons outside and below the grid makes the grid smaller and puts more white space into the mix.

Yes, I was getting that message, although I though that BeforeRowInsert was firing before I got that event (although there seemed to be nothing I could do to create the data before it continued on... unless I could cancel.. hmm.

Andy

leyh replied on Thursday, September 28, 2006

Hi,

I have a somewhat related question regarding the AddNew button.

Is it possible to bind the following data structure to a 2-band UltraGrid:

BOList and BOList

I receive the error message "Row insertion not supported by this data source." when I try to create a new row in BOList using the AddNew button.

Thanks in advance.

Leyh

leyh replied on Thursday, September 28, 2006

leyh:
Hi,

I have a somewhat related question regarding the AddNew button.

Is it possible to bind the following data structure to a 2-band UltraGrid:

BOList and BOList

I receive the error message "Row insertion not supported by this data source." when I try to create a new row in BOList using the AddNew button.

Thanks in advance.

Leyh


I forgot to mention I am using version 2.03

cheers,

Leyh

ajj3085 replied on Thursday, September 28, 2006

Make sure BOList has its AllowNew property set to true; also make sure the BindingSource to which BOList is bound has its AllowNew property set to true.  Finally, make sure the grid allows new objects.

HTH
Andy

leyh replied on Thursday, September 28, 2006

Andy,

The AllowNew property of the two BOList is already set to true. However, only still the first band can accpet new

objects but NOT the second band.

Binding a nested List to the second band on the other hand is fine.

ie. This is ok.
class Items : BOList
{
private List listOfSubItems; // This is exposed as property
}

but not this one

class Items : BOList{}; // Ok to add a new object.
class Item : BOList{}; // CAN'T add a new object

Is there anything speical with binding a sub-BOList(ie the Item BOList) to the second band?

Thanks in advance,

Leyh

ajj3085 replied on Thursday, September 28, 2006

Hmm, I wouldn't think that Item would subclass BOList

Also, you don't need to have a List to store the items in your Items class. BOList is itself a collection (assuming BOList inhertis BusinessListBase, which I would think it should).

leyh replied on Thursday, September 28, 2006

Please disregard my previous post. The angle brackets didn't show up properly.

Andy,

The AllowNew property of the two BOList is already set to true. However, only still the first band can accpet new objects but NOT the second band.

Binding a nested List{BO} to the second band on the other hand is fine.

ie. This is ok.
class Items : BOList { Items, Item }
{
private List { SubItems } listOfSubItems; // This is exposed as property
}

but not this one

class Items : BOList { Items, Item } {}; // Ok to add a new object.
class Item : BOList { Item, SubItem } {}; // CAN'T add a new object

Basically Items contains a list of items and each item contains a list of sub items.

Is there anything speical with binding a sub-BOList(ie the Item BOList) to the second band?

Thanks in advance,

Leyh

vandero replied on Friday, October 13, 2006

Hello,

I'm having the same problem as what you describe. In an UltraGrid I cannot add records to a child band. The grid is bound to a BusinessListBase object Contacts, that contains Contact objects that each have a BusinessListBase collection ContactPersons of ContactPerson objects.

Adding rows to the parent band works but when I try to add a row to the child band then I get the error: "Row insertion not supported by this data source.".

Also, I looked into the BusinessListBase objects themselves (which inherit from BindingList<>) and it seems that both for the parent and child the AllowNew is set to False which seems strange to me because adding a row to Contacts DOES work.

Does anybody have a solution to this? Is it a problem related to UltraGrid or does anybody else have this problem also with another grid control?

Thanks in advance,

Robin

ajj3085 replied on Friday, October 13, 2006

You have to set AllowNew on the collection, and also on any binding source controls your have as well.  Sometimes they set themselves to False by default.

You'll have to do what I did to add the rows which require data to create; a button outside the grid which will gather the data, call the factory method for the object, then call Add on the appropriate binding source object.  That last part is important because you'll want to keep the BindingSource 'in the loop,' so to speak.

HTH
Andy

themanfromsql replied on Wednesday, March 28, 2007

Hello,

I was having the same problem with a nested List<T> and getting the error message above.  My problem was due to the fact that the nested List's type T didn't have an empty constructor.  I had a single constructor that took in a string value.  As soon as I created a second empty constructor, it started allowing me to add nested types. 

Copyright (c) Marimer LLC