Hi all,
I have the grid that allows a user to add rows to it. I would like to do it via providing an empty last row. As the user starts typing into it, the next empty row appears.
Of course I realize, that the datasource should be modified when that new row is added.
Is there a common solution for this?
Thanks,
Vitaly
Hi Vitaly,
The way this works is that there are 3 types of rows - or really three states for the row.
The TemplateAddRow is the row you see in the grid all the time. This is not, in fact, a "real" row. It has no representation in the data source. It's just a placeholder.
Once the user makes any kind of edit to the TemplateAddRow, it becomes an AddNew row and a new TemplateAddRow is added. At this point, the AddNew row exists as an AddRow in the Data source.
So Petar's suggestion above will give you default values in the AddNew row as soon as the user begins to edit it. This might be a little weird, though. Because if the user starts editing a cell in the TemplateAddRow, it will become an AddRow, at which point InitializeRow will fire and you might end up overwriting what the user types with your defaults.
So typically, it's better to set the defaults in the InitializeTemplateAddRow event or use the DefaultCellValue property on the column.
Regarding editors, if you want different editors in the TemplateAddRow/AddNew row than in the other rows of the grid, this is a bit tricky. You would have to apply the editor to each cell.
What I would do is use the InitializeRow event and check for IsAddRow or IsTemplateAddRow and then you can set the Editor or EditorControl on the cells in the row. So for example, you could set the editor if the row is an TemplateAddRow, then reset the Editor if it's just a regular data row so that the row will revert to using the default editor for the column.
Hi,
When you click the AddNew row a ne row is automatically created so you can use the InitializeRow to do something like this:
private void ultraGrid1_InitializeRow(object sender, InitializeRowEventArgs e){ if (e.Row.IsAddRow) { e.Row.Cells[0].Value = 0; e.Row.Cells[1].Value = 0; .... }}
Hope this helps.
Regards Petar
Thanks for the response.
One more question on this. Is there a way to configure cells state of the 'AddNew' row? For example, in my 'AddNew' row I would like to have custom cells editors, my own default value of each cell, etc?
-Vitaly
Hello Vitaly,
This exact behaviour is implemented in the ultraGrid. You simply need to set the AlloAddNew property e.g.:
ultraGrid1.DisplayLayout.Override.AllowAddNew =
AllowAddNew.TemplateOnBottom;
Sincerely,
Petar Monov
Developer Support Engineer,
Infragistics, Inc