Greetings,
I'm trying to implement a custom action to create a new row to a listview when clicken in the default new button, as like the behaviour of the edit inline.
Best regards.
Greetings,
I'm trying to implement a custom action to create a new row to a listview when clicken in the default new button, as like the behaviour of the edit inline.
Best regards.
Hello Jorge,
Thank you for the clarification. In this case, you can handle the NewObjectAction.Executing event to cancel New Action executing and use the Access Grid Control Properties to access ASPxGridView and use the AddNewRow method.
Here is a code snippet for the ViewController:
C#protected override void OnActivated() {
base.OnActivated();
Frame.GetController<NewObjectViewController>().NewObjectAction.Executing += new System.ComponentModel.CancelEventHandler(NewObjectAction_Executing);
}
void NewObjectAction_Executing(object sender, System.ComponentModel.CancelEventArgs e) {
e.Cancel = true;
ASPxGridListEditor listEditor = ((ListView)View).Editor as ASPxGridListEditor;
if(listEditor != null) listEditor.Grid.AddNewRow();
}
I have attached a video that illustrates this approach.
Update:
In newer versions, you can implement this on the client side to achieve better performance. Use the SupportClientScriptsExtensions.SetClientScript extension method to execute a custom script when the New action is clicked:
C#using System;
using DevExpress.ExpressApp;
using DevExpress.ExpressApp.SystemModule;
using DevExpress.ExpressApp.Actions;
using DevExpress.ExpressApp.Web.Editors.ASPx;
using DevExpress.Web;
namespace MainDemo.Module.Web {
public class StartInlineEditingController : ViewController<ListView> {
public StartInlineEditingController() {
TargetViewNesting = Nesting.Nested;
}
protected override void OnViewControlsCreated() {
base.OnViewControlsCreated();
if (((IModelListViewNewItemRow)View.Model).NewItemRowPosition != NewItemRowPosition.None) {
ASPxGridListEditor gridListEditor = View.Editor as ASPxGridListEditor;
if (gridListEditor != null) {
gridListEditor.Grid.Load += Grid_Load;
}
}
}
private void Grid_Load(object sender, EventArgs e) {
ASPxGridView gridView = (ASPxGridView)sender;
gridView.Load -= Grid_Load;
NewObjectViewController newObjectViewController = Frame.GetController<NewObjectViewController>();
if (newObjectViewController != null) {
newObjectViewController.NewObjectAction.SetClientScript(gridView.ClientID + ".AddNewRow();", false);
}
}
}
}
Greetings,
Thank you for your support and helping me to get this fixture.
Best regards.
Disclaimer: The information provided on DevExpress.com and affiliated web properties (including the DevExpress Support Center) is provided "as is" without warranty of any kind. Developer Express Inc disclaims all warranties, either express or implied, including the warranties of merchantability and fitness for a particular purpose. Please refer to the DevExpress.com Website Terms of Use for more information in this regard.
Confidential Information: Developer Express Inc does not wish to receive, will not act to procure, nor will it solicit, confidential or proprietary materials and information from you through the DevExpress Support Center or its web properties. Any and all materials or information divulged during chats, email communications, online discussions, Support Center tickets, or made available to Developer Express Inc in any manner will be deemed NOT to be confidential by Developer Express Inc. Please refer to the DevExpress.com Website Terms of Use for more information in this regard.
Hello Jorge,
Do you need a solution for WinForms or ASP.NET?
THe solution that I need is for ASP.NET
Best regards.