Quantcast
Channel: DevExpress Support Center (Examples)
Viewing all 7205 articles
Browse latest View live

ASPxGridView - Batch Editing - A simple implementation of an EditItem template

$
0
0

This example demonstrates how to create a custom editor inside column's DataItem template when ASPxGridView is in Batch Edit mode. Since, ASPxGridView performs batch editing on the client side, we cannot process or pass values from editors placed inside templates on the server side. Thus, all processing will be performed on the client side. 


You can implement the EditItem template for a column by performing the following steps:

1. Specify column's EditItem template:

[ASPx]
<dx:GridViewDataColumnFieldName="C1"><EditItemTemplate>  <dx:ASPxSpinEditID="C1_spinEdit"runat="server"ClientInstanceName="C1spinEdit"Width="100%">  </dx:ASPxSpinEdit></EditItemTemplate></dx:GridViewDataColumn>


2. Handle grid's client-side BatchEditStartEditing event to set the grid's cell values to the editor. It is possible to get the focused cell value using the e.rowValues property:

[JScript]
       function Grid_BatchEditStartEditing(s, e){           var productNameColumn = s.GetColumnByField("C1");           if(!e.rowValues.hasOwnProperty(productNameColumn.index))               return;           var cellInfo = e.rowValues[productNameColumn.index];            C1spinEdit.SetValue(cellInfo.value);           if(e.focusedColumn === productNameColumn)                C1spinEdit.SetFocus();       }


3. Handle the BatchEditEndEditing event to pass the value entered in the editor to the grid's cell:

[JScript]
function Grid_BatchEditEndEditing(s, e){var productNameColumn = s.GetColumnByField("C1");if(!e.rowValues.hasOwnProperty(productNameColumn.index))return;var cellInfo = e.rowValues[productNameColumn.index]; cellInfo.value = C1spinEdit.GetValue(); cellInfo.text = C1spinEdit.GetText(); C1spinEdit.SetValue(null);}

 

4. The BatchEditRowValidating event allows validating the grid's cell based on the entered value:

[JScript]
function Grid_BatchEditRowValidating(s, e){var productNameColumn = s.GetColumnByField("C1");var cellValidationInfo = e.validationInfo[productNameColumn.index];if(!cellValidationInfo)return;var value = cellValidationInfo.value;if(!ASPxClientUtils.IsExists(value) || ASPxClientUtils.Trim(value) === ""){ cellValidationInfo.isValid = false; cellValidationInfo.errorText = "C1 is required";}}

 
5. Finally, handle the editor's client-side KeyDown and LostFocus events to emulate the behavior of standard grid editors when an end-user uses a keyboard or mouse:

[JScript]
var preventEndEditOnLostFocus = false;function C1spinEdit_KeyDown(s, e){var keyCode = ASPxClientUtils.GetKeyCode(e.htmlEvent);if(keyCode !== ASPxKey.Tab && keyCode !== ASPxKey.Enter)return;var moveActionName = e.htmlEvent.shiftKey ? "MoveFocusBackward" : "MoveFocusForward";if(grid.batchEditApi[moveActionName]()){ ASPxClientUtils.PreventEventAndBubble(e.htmlEvent); preventEndEditOnLostFocus = true;}}function C1spinEdit_LostFocus(s, e){if(!preventEndEditOnLostFocus) grid.batchEditApi.EndEdit(); preventEndEditOnLostFocus = false;}

 
See Also:
GridView - Batch Editing - A simple implementation of an EditItem template 



How to add zooming to PictureEdit

$
0
0

This example is obsolete. Currently, this feature is supported out-of-the-box



This example demonstrates how to add the zooming feature to the PictureEdit control. We have created a PictureEdit descendant and added a ZoomFactor property indicating the current picture's zoom factor in percents.

OBSOLETE - How to implement Controller or Action that will be active only in the "My Details" window

$
0
0

===============================
This example is now obsolete. Instead, use the built-in CurrentUserId criteria function.
===============================

This example shows how to implement a ViewController, containing Actions, that will be active only in the "My Details" window.
In order to do this, we will set the TargetViewId property either of the ViewController or Action objects at design time. Take special note that this Id will vary against the type of the Security System (Simple or Complex) used in the application, because there are different user types for them.
To solve this problem in a more elegant way, we will also configure an Action at runtime, but set its properties against the properties of the SecuritySystem singleton.

See Also:
How to remove or hide (deactivate, disable) a button ( Action ) from tool bar
ActionBase.TargetObjectsCriteria

ASPxGridView - How to disable editing for rows that match some condition in Batch Edit Mode

ASPxGridView - Batch Editing - How to cancel editing or disable the editor conditionally

$
0
0

This example demonstrates how to cancel editing or disable the editor conditionally for the grid when batch editing is in use. It is possible to execute your logic either on the client or server side for a complex business model.
Then, handle the grid's client-side BatchEditStartEditing event to either cancel the edit operation using the e.cancel property:

[JScript]
if(condition) e.cancel = true;

 or disable the editor by obtaining its client instance:

[JScript]
var editor = s.GetEditor(e.focusedColumn.fieldName); editor.SetEnabled(condition);

 The custom server-side logic can be executed in the CustomJSProperties event handler:

[C#]
protectedvoidASPxGridView1_CustomJSProperties(objectsender,DevExpress.Web.ASPxGridView.ASPxGridViewClientJSPropertiesEventArgse){varclientData=newDictionary<int,object>();vargrid=senderasASPxGridView;for(inti= 0;i<grid.VisibleRowCount;i++){varrowValues=grid.GetRowValues(i,newstring[]{"ID","ServerSideExample"})asobject[];varkey=Convert.ToInt32(rowValues[0]);if(key% 2 != 0)clientData.Add(key,"ServerSideExample");}e.Properties["cp_cellsToDisable"]=clientData;}

 

See Also:
ASPxGridView - How to disable editing for rows that match some condition in Batch Edit Mode
GridView - Batch Editing - How to cancel editing or disable the editor conditionally

OBSOLETE - How to prevent a popup window from closing

$
0
0

==============================
This example is now obsolete. Instead, handle the DialogController.QueryViewCanClose event, which is a more universal solution for this scenario (see Q490762 for some example code).
==============================
This example demonstrates how to manage the closing of a popup window via the CanCloseWindow property of the DialogController.

OBSOLETE - How to customize the standard Printing module

$
0
0

===================================
This example is now obsolete. Refer to the How to: Customize Export Options of the Printing System  help topic instead.
===================================
This example shows how to override the behavior of the standard PrintingController to provide custom drawing in the Preview window.

See Also:
Reports - Introduce an ability to set PrintingSystem command handlers into XafReport
How to customize print preview settings when using Reports, Analysis and Printing modules in Windows Forms applications
http://search.devexpress.com/?q=PrintableComponentLink&p=1009075&d=144
http://search.devexpress.com/?q=Printing&p=1006092&d=144

Question Comments

Added By: Ferraro at: 5/24/2012 10:18:32 PM    

This is working great, but the user have to manually enlarge the header and the footer to see the custom text.
Is there a way to do it automatically by code ?

How to validate objects when navigating between records and the list view is in the ListViewAndDetailView mode.

$
0
0

=================================
This example is now obsolete. Instead, set the ModificationsController.ModificationsHandlingMode property to AutoCommit.
=================================

By default, XAF objects are not immediately validated when moving between records in the list or detail view and when using the navigation buttons or selecting records in the grid. This example demonstrates how to work around this design and prompt a user once he is about to leave the edit mode and go to another record.


OBSOLETE - How to analyze selected data directly from a view - In place Analysis

$
0
0

=================================
This example is now obsolete. Instead, refer to the How to: Add the Analyze Action to List Views topic in XAF documentation.
=================================
This example is a possible solution for the PivotChart - Support inplace analysis feature feature request. The main work is done by the ShowInAnalysisViewController and two helper controllers that provide a ShowInAnalysis action with the ability to select the required report.
To use it, first select the required objects in the view, and then execute the ShowInAnalysisAction action. In general, this feature works very similarly to the analogous feature for our Report module described here: Show Reports for Individual Views.
 
See Also:
PivotChart - Support inplace analysis feature
How to Add the Analyze Action to List Views

OBSOLETE - How to show info from several properties in the lookup editor when it is closed

GridView - Batch Editing - A simple implementation of an EditItem template

$
0
0

This example demonstrates how to create a custom editor inside column's DataItem template when GridView is in Batch Edit mode.

You can implement the EditItem template for a column by performing the following steps:

1. Specify column's EditItem template:

[C#]
       settings.Columns.Add(column=>       {           column.FieldName="C1";           column.SetEditItemTemplateContent(c=>           {               @Html.DevExpress().SpinEdit(spinSettings=>               {                   spinSettings.Name="C1spinEdit";                   spinSettings.Width=System.Web.UI.WebControls.Unit.Percentage(100);                   spinSettings.Properties.ClientSideEvents.KeyDown="C1spinEdit_KeyDown";                   spinSettings.Properties.ClientSideEvents.LostFocus="C1spinEdit_LostFocus";               }).Render();           });       });


2. Handle grid's client-side BatchEditStartEditing event to set the grid's cell values to the editor. It is possible to get the focused cell value using the e.rowValues property:

[JScript]
       function Grid_BatchEditStartEditing(s, e){           var productNameColumn = s.GetColumnByField("C1");           if(!e.rowValues.hasOwnProperty(productNameColumn.index))               return;           var cellInfo = e.rowValues[productNameColumn.index];            C1spinEdit.SetValue(cellInfo.value);           if(e.focusedColumn === productNameColumn)                C1spinEdit.SetFocus();       }


3. Handle the BatchEditEndEditing event to pass the value entered in the editor to the grid's cell:

[JScript]
function Grid_BatchEditEndEditing(s, e){var productNameColumn = s.GetColumnByField("C1");if(!e.rowValues.hasOwnProperty(productNameColumn.index))return;var cellInfo = e.rowValues[productNameColumn.index]; cellInfo.value = C1spinEdit.GetValue(); cellInfo.text = C1spinEdit.GetText(); C1spinEdit.SetValue(null);}

 

4. The BatchEditRowValidating event allows validating the grid's cell based on the entered value:

[JScript]
function Grid_BatchEditRowValidating(s, e){var productNameColumn = s.GetColumnByField("C1");var cellValidationInfo = e.validationInfo[productNameColumn.index];if(!cellValidationInfo)return;var value = cellValidationInfo.value;if(!ASPxClientUtils.IsExists(value) || ASPxClientUtils.Trim(value) === ""){ cellValidationInfo.isValid = false; cellValidationInfo.errorText = "C1 is required";}}

 
5. Finally, handle the editor's client-side KeyDown and LostFocus events to emulate the behavior of standard grid editors when an end-user uses a keyboard or mouse:

[JScript]
var preventEndEditOnLostFocus = false;function C1spinEdit_KeyDown(s, e){var keyCode = ASPxClientUtils.GetKeyCode(e.htmlEvent);if(keyCode !== ASPxKey.Tab && keyCode !== ASPxKey.Enter)return;var moveActionName = e.htmlEvent.shiftKey ? "MoveFocusBackward" : "MoveFocusForward";if(grid.batchEditApi[moveActionName]()){ ASPxClientUtils.PreventEventAndBubble(e.htmlEvent); preventEndEditOnLostFocus = true;}}function C1spinEdit_LostFocus(s, e){if(!preventEndEditOnLostFocus) grid.batchEditApi.EndEdit(); preventEndEditOnLostFocus = false;}

 
 
See Also:
ASPxGridView - Batch Editing - A simple implementation of an EditItem template 

How to implement conditional formatting for rows

$
0
0

The following sample demonstrates how to change the appearance of grid rows based on some condition. For example, in this tutorial you can see that the background color of grid rows is gradually changed based on the value in the second data column.

This is done by binding the Background property of a style, assigned to a row, to a color converter. This converter is represented by the ColorValueConverter class that implements the IValueConverter interface and returns a color according to the provided numerical value.

Updated:

In v14.1, we implemented this functionality out-of-the-box. Please refer to the Conditional Formatting help topic for details.

Question Comments

Added By: Fahad at: 7/9/2013 3:50:45 AM    

Is there an easy way to Style each cell ? Or we have to use DataTemplate ?

Added By: Mary Roy at: 6/5/2014 1:46:45 PM    

Your sample does not work

Added By: Michael Ch (DevExpress Support) at: 6/6/2014 12:42:08 AM    Hello Mary,

Thank you for your remark. I have corrected this sample. Please review it.

Thanks,
Michael

How to customize a message dialog displayed when runtime errors occur

$
0
0

This example demonstrates how to display a custom message in a custom manner instead of the default user warning dialog box.
Сreate a class that implements the IMessageBox service and register that class in place of the default service by using the SpreadsheetControl.ReplaceService method.
The IMessageBox service provides the ShowOkCancelMessage, ShowWarningMessage and ShowYesNoMessage (available starting from v2014 vol.1) methods which are called in specific situations when the SpreadsheetControl needs user attention.

How to deploy a WPF Report Designer on the client

$
0
0

This example illustrates how you can deploy a WPF Report Designer on the client (without a reporting server).


To deploy the WPF Report Designer locally, do the following.

1. Substitute the default client for the Report Designer with a custom one.

1.1. Create a custom client (in this sample, see LocalReportDesignerClient) that implements the IReportDesignerServiceClient interface. All methods of this interface are delegated from ReportService that is defined as a field or property in this client.

1.2. The client can refer to a ReportService type object, but it does not implement saving/loading of a report layout. For this reason, add an extension class that implements IDesignerReportStore interface (in this sample, see LocalDesignerReportStore class showing a simplified implementation of the LoadLayout and SaveLayout methods of the IDesignerReportStore interface).
 1.3. In this sample, the Abort and CloseAsync methods in LocalReportDesignerClient are intentionally left empty, because they are not required.

1.4. Since the ReportDesignerViewModel exposes not the client, but its factory, you need to create this factory as well (in this sample, LocalReportDesignerClientFactory) and assign it to the Designer’s view model (in this sample, see MainWindow.xaml.cs).

2. For the ReportDesignerViewModel, specify a report's name and namespace, as well as a fake ServiceUri.


See also: How to use a WPF Report Designer in a client-server mode.

Question Comments

Added By: Xavier de LURION at: 9/19/2012 7:21:57 AM    

In your exemple, you use a Report designed in Visual Studio, but how do you do to load it from database ?

Added By: Ramesh Supekar at: 6/6/2014 2:58:34 AM    

For the example here in downloads

In ribbon control Watermark button click  gives null reference error , Please guide how to fix this .

How to determine which series point is located under the test point

$
0
0

This example demonstrates how to handle the ChartControl.MouseMove event, to determine which series point is located under the test point and show the information about its argument and value using the DevExpress.Utils.ToolTipController.

 Note that starting from v2012 vol 1, the chart control supports built-in tooltips.


How to bind a Map control to a datasource

$
0
0

This example illustrates how to bind a Map control to data. This data stored in an external XML file, which contains information about wrecked ships, including ship coordinates.

In this example, the map control automatically generates ship images based on data from the datasource, along with a description for each image in a tooltip.

Question Comments

Added By: Stefán Höskuldsson at: 8/21/2013 2:57:31 AM    

In this example below you are always using the same image for each item. If I wanted different images (like based on type of ship) could I somehow use the MapItemAttributeMapping to map to an Image or an ImageIndex in the Ship class?

How to create an Overlapped Gantt chart

How to create a Side-by-Side Gantt chart

Validation - How to highlight invalid properties when the View is shown

$
0
0

This example demonstrates, how to check rules when the View is activated, or the View's object is changed. For that purpose, the ImmediateValidationController is implemented. To avoid checking these rules when the business object is saved or deleted, their context is set to Custom.

Question Comments

Added By: Robert Emslie 1 at: 6/6/2014 6:00:21 AM    

This controller causes serious performance issues where validation requires database reads for uniqueness etc.

How to create a real-time chart

Viewing all 7205 articles
Browse latest View live


<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>