Having a Grid with a Fixed AddRow at the top.
I set the AddRowPrompt to something the user understands, like:
this.dfgrid1.DisplayLayout.Override.TemplateAddRowPrompt = "click here to add something new";
This works and looks fine. Only the Prompt is displayed in that first Grid-Line and if the user clicks, that prompt goes away.
NOW i like to preset the cell values of the AddRow, so that the user only needs to override values that doesn't fit.
the Goal is:
- The User should click on that AddPrompt to get a new line that is prefilled with values, tab thru / correct values - finished.
I thought, the event "InitializeTemplateAddRow" could be a good idea so i did this:
this.dfgrid1.InitializeTemplateAddRow += dfgrid1_InitializeTemplateAddRow;
void dfgrid1_InitializeTemplateAddRow(object sender, InitializeTemplateAddRowEventArgs e) { e.TemplateAddRow.Cells["Bezeichnung"].Value = "Neue Wiedervorlage"; e.TemplateAddRow.Cells["An"].Value = "Grote, Gunnar"; DateTime dt = new DateTime(2015, 02,20, 00, 00, 00); e.TemplateAddRow.Cells["Datum"].Value = dt; e.TemplateAddRow.Cells["Status"].Value = "offen"; }
well - technically this works, the cells are preset but there are 2 problems:
1.) This Initialization is running when the grid is initialized - Not when the user clicks on the AddRowPrompt to start editing. This means: Now i have prefilled Cells, overlayed with the AddRowPrompt - looking very horribly / unreadably :)
2.) If the user just Tabs thru the new Row (because every preset values fits perfectly), no new Row is beeing added (i think because the Grid didn't noticed any change event?)
Any ideas to make it look better? (preset cell values only after the user clicks on the addRow - or after the user adds the row (enter / tab on last field) and is getting on the first cell again)
Any ideas how to make the Grid add the row even if the user didn't overwrite the preset values?
Hey Dimitar,
i have absolutely no idea how one could come to such solution without working at infragistics for years :) - But it works!
Thanks a lot!
Boris
Hi,
Thank you for posting in our forums.
1) You can use the DrawFilter interface to draw over the cell values in order to hide the text. In the GetPhasesToFilter method return the AfterDrawChildElements if the element is CellUIElement, its row is TemplateAddRow and the row isn’t active. In the DrawElement use the graphics object of the drawParams to Fill the Cell and hide its content.
2) You can use the AddRowModifiedByUser property. If this property is set to true, the AddRow will be added to the Rows collection. You can use the KeyDown event - check if the tab key was pressed, the active row is the AddRow and if the active cell is the last visible cell.
I have attached a sample demonstrating this approach.
Let me know if you have any additional questions.