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

How to use DelegateCommand


How to use the POCO mechanism

How to generate and send e-mails (bulk mail) while iterating through datasource records

$
0
0

In some scenarios, you need to generate e-mail letters and send them while iterating through some datasource records.

Let's consider the following scenario. We have a master-detail database. A master table contains information about customers whom we need to send letters. A detail table contains information to generate letters.


To generate and send letters, we need to perform the following actions while iterating through the data source:

1. Create a filtered view from the child table based on the customer's ID.

2. Use this view as a SnapControl's mail merge data source.

3. Iterate through this view records.

4. Perform the mail-merge operation.

5. Generate an e-mail letter based on the SnapControl's document as demonstrated in the following example: How to export the RichEditControl document into an Outlook mail item

You may notice only one issue. The content of some letters will be generated incorrectly.

This occurs since the loading of the mail template into the SnapControl is executed asynchronously and can require more time than iterating to the next datasource record.

When a document is completely loaded into the SnapControl (or RichEditControl), the DocumentLoaded event is raised.


To avoid the issue with an incorrectly generated content of a letter, you need to send letters in the DocumentLoaded event handler.

We recommend saving generated letters in a temporary folder while iterating through datasource records.

After all letters are saved, load these files and send the letters synchronously in the SnapControl.DocumentLoaded event handler.

This example demonstrates this approach in action.

How to bind a dashboard to a List object

$
0
0

The following example demonstrates how to bind a dashboard to a List object.


In this example, information about the sold units quantity is provided at runtime. The dashboard data source is created via the Dashboard.AddDataSource method on the first load.

To update the displayed data, the DashboardViewer.ReloadData method is called. This raises the DashboardViewer.DataLoading event and allows supplying the dashboard with updated data.

How to bind ASPxGridView to data when clicking an external button

$
0
0

This example illustrates how to bind ASPxGridView to data when clicking an external button.


Note that if the grid is already bound to another datasource, it is necessary to set the grid's EnableViewState property to False.

Also, clear the grid's columns and set the AutoGenerateColumns property to True before calling the DataBind method.

How to put a custom UserControl in a GridView cell

$
0
0

NOTE:
This example is created only for demonstration purposes and we don't recommend using this approach in your application, because it has many limitations and requires writing a lot of custom code. If none of DevExpress XtraEditors are suitable for you and you want to put a custom control in a GridControl cell, pleasecontact DevExpress support and describe the desired layout to us. We will do our best to find an acceptable solution for you.

This example demonstrates how a custom UserControl can be used as an in-place editor in GridView, TreeList, Ribbon and Vertical Grid. As described in the A128 Knowledge Base, it is not possible to just place a control within a cell, because cells are not controls. When a cell's editor is not activated, its content is drawn via a painter. So, in our example, we have created a painter to draw the entire UserControl's content. All cells in GridView will be drawn using this painter until an end-user clicks a cell. In this case, an actual instance of the UserControl class will be created. Controls inherited from the BaseEdit class are drawn via their painters, other controls are drawn via the DrawToBitmap function. In case of 3rd-party controls, you need to draw them manually. If you want to use your custom control in GridView or other controls, you need to implement the IEditValue interface in it.

See also: How to work with the editor's painter, and view info classes in a descendant

Example Comments

Added By: Jaix Software at: 3/6/2013 8:05:36 PM    

This example does not work with DateEdit in a menu bar. There appears to be a display issue, as when focus is lost nothing is display. Re-selecting the control and the dates come back.

Added By: D. Samsonoff at: 4/25/2013 2:58:12 AM    

You probably would want to expose Control rather than UserControl to meet broader requirements.

Added By: Christophe Keller @ PTS at: 12/12/2013 1:34:26 AM    

Hi,

In your example, if I click on a different cell in the table in Form1, the cell turns white for a short amount of time before the editor is active. How can I avoid this?

How to create a ButtonEdit descendant that can show a multi-line text like MemoEdit

$
0
0

This example shows how to create and use a ButtonEdit descendant that will support multi-line text like MemoEdit.


This descendant's repository items have three additional properties:

RepositoryItemMultiLineButtonEdit.AcceptsReturn - gets or sets a value specifying whether return characters can be inserted into text.
RepositoryItemMultiLineButtonEdit.AcceptsTab - gets or sets a value specifying whether a user can insert tab characters into text.
RepositoryItemMultiLineButtonEdit.ScrollBars - gets or sets a value indicating which scrollbars are displayed.

See also:
Custom Editors.

How to create a ButtonEdit descendant that can show a multi-line text like MemoEdit

ASPxGridView - How to sort a grid column by its values and its group summary at the same time

$
0
0

This example demonstrates how to implement the following behavior:
When a column is sorted, the grid displays groups based on the column's group summary value. Rows inside the group are also sorted based on the column's sort order.

To do so, it is necessary to:
1) Save the column's sort order in the grid's BeforeGetCallbackResult event handler;
2) Restore this state in the grid's Init event hander.


How to add a "Custom" filter item into the date filter popup

ASPxEditors - How to show a validation image tooltip immediately

$
0
0

The Error tooltip is a standard html title attribute. So, we cannot reduce the delay when displaying it. However, we can use a custom tooltip via the ASPxPopupControl.

How to: Use the POCO Mechanism to implement the IDataErrorInfo Interface

$
0
0

This Code Example demonstrates how you use the POCO mechanism to implement the IDataErrorInfo interface.

For more information about POCO, refer to the following topic: DevExpress MVVM Framework. Introduction to POCO ViewModels.

The following article describes how to automatically generate an IDataErrorInfo implementation: DevExpress MVVM Framework. Data validation. Implementing IDataErrorInfo.


Example Comments

Added By: Jimmy Larkin at: 3/18/2014 7:35:05 AM    

Great you guys did that. Two questions though:
1. How to make the form validated only when the user changes anything? Currently all fields are validated immediately after the form is loaded so when the form opens errors are displayed straight away.
2. A button executes a command on my ViewModel. How can I test if the model is valid?

Added By: Jimmy Larkin at: 3/18/2014 7:36:20 AM    

One more question. I found that the button set up as in example below is not disabled despite errors.

Added By: Vladimir M (DevExpress) at: 3/19/2014 5:46:30 AM    

Hi Jimmy,

Those are great questions.

1. Let's consider validation and the visual cues generated by the editors separately. If we prevented validation on startup, the button would be enabled initially, which is probably not what we want, given that the data is clearly invalid at this point. Just preventing errors from being displayed seems to be a valid solution. Our editors have the ShowError property for this. So, for starters we disable visual cues at startup as follows:

<dxe:TextEdit ... ShowError="False"/>

Now we need to enable the property at an appropriate time. I think it makes sense enabling it when the control loses focus. So, we want to update ShowError when the UIElement.LostKeyboardFocus event is fired.

To achieve this, I will use attached behavior:

public class DelayedValidationResponseBehavior : Behavior<BaseEdit> {
    protected override void OnAttached() {
        base.OnAttached();
        AssociatedObject.LostKeyboardFocus += AssociatedObject_LostKeyboardFocus;
    }
    protected override void OnDetaching() {
        AssociatedObject.LostKeyboardFocus -= AssociatedObject_LostKeyboardFocus;
    }
    void AssociatedObject_LostKeyboardFocus(object sender, RoutedEventArgs e) {
        if(!AssociatedObject.IsFocused)
            AssociatedObject.ShowError = true;
    }
}

The behavior is used as follows:

<dxe:TextEdit NullText="First"
              Text="{Binding FirstName,
                    ValidatesOnDataErrors=True,
                    UpdateSourceTrigger=PropertyChanged}"
              ShowError="False">
    <dxmvvm:Interaction.Behaviors>
        <local:DelayedValidationResponseBehavior/>
    </dxmvvm:Interaction.Behaviors>
</dxe:TextEdit>

Now errors will only show up after the control has lost focus at least once.

2. I will use a service to get the ValidationService.GetHasValidationError value in the ViewModel.

The service:

public interface IValidationErrorsService {
    bool HasErrors { get; }
}
public class ValidationErrorsService : ServiceBase, IValidationErrorsService {
    public bool HasErrors {
        get {
            if(AssociatedObject == null)
                return false;
            return ValidationService.GetHasValidationError(AssociatedObject);
        }
    }
}

The View:

<dxlayout:LayoutControl dxe:ValidationService.IsValidationContainer="True">
        <dxmvvm:Interaction.Behaviors>
            <local:ValidationErrorsService x:Name="ValidationErrorsService"/>
        </dxmvvm:Interaction.Behaviors>
        ...
</dxlayout:LayoutControl>

The ViewModel:

public class SignupViewModel : ViewModelBase {
    public virtual IValidationErrorsService ValidationErrorsService { get { return null; } }
    bool HasValidationErrors { get { return ValidationErrorsService.HasErrors; } }
    ...
}

The ValidationErrorsService property will be overridden by the POCO mechanism to return our service's instance from the View.

Would you please elaborate on the enabled button? Can this behavior be reproduced in our sample? If not, then would you post an application that illustrates the problem?

How to: Create a Custom Service

How to: Create a Custom Service

How to keep master and detail view column widths synchronized

$
0
0

When you have a master-detail view and for some reason don't want to use the AutoColumnWidth option, the detail view is still stretched to accommodate the entire master view's width. So, in this example we've decided to create a grid view that changes this behavior and synchronizes the detail view's width with the mater view's columns.
We create and register a GridView descendant that introduces the AutoSynchronizeDetailsLayout option by using a descendant of the GridOptionsView class. If this option is enabled and the AutoColumnWidth option is disabled the new behavior takes effect. The detail view's width is now calculated based on the master view columns' width, so, the detail view ends up with the last master view's column.
In addition, if the number of detail and master view columns is equal, the detail view's columns are aligned with that of the master view for even a smoother view.

Example Comments

Added By: andrei shannou at: 8/9/2013 5:46:31 AM    

Thanks,

It works, but a little buggy. Try to group a grid by any column, then change the width of any column. I seems to fall in infinite loop. Tried to find out why, but failed. Will appreciate your help if any.

Added By: andrei shannou at: 8/9/2013 6:39:35 AM    

Got it. Should be

                        rowVisibleIndex = GetNextVisibleRow(rowVisibleIndex);
                        rowHandle = GetRowHandle(rowVisibleIndex);

Added By: andrei shannou at: 8/9/2013 7:00:51 AM    

by the way, horizontal scrolling is also broken :-(

FileManager - How to show a confirmation dialog to overwrite an existing file

$
0
0

This example illustrates how to show a conformation message to overwrite an existing file in the ASPxFileManager.


The conformation message is shown in the client-side ASPxClientFileManager.FileUploading event and gives an option to the user to either overwrite the existing file or cancel the operation. User's selection is then transferred to the server-side via an ASP.Net MVC Helper Html.Hidden. If the user chooses to overwrite the file, the existing file will be deleted in the ASPxFileManager.FileUploading event.


How to bind ASPxScheduler to ObjectDataSource

$
0
0

In this example, the ObjectDataSource control is used to bind the ASPxScheduler control to middle-layer business objects. Further, you can implement your own custom CRUD-operations (Create, Read, Update, Delete – a common abbreviation for data operations) using an arbitrary data provider.

To make the project simple and easy-to-use, data is written into a session.

See Also:
How to bind ASPxScheduler to ObjectDataSource
How to bind ASPxScheduler to MS SQL Server database
How to bind ASPxScheduler to XPO via the Unit of Work
How to bind ASPxScheduler to SyBase ASE 15 database

How to download files from a specific ASPxGridView's column

$
0
0

This example illustrates how to create a column whose cells are rendered as links with icons. Once the link is clicked, the file that corresponds to the current row starts downloading. Here is a downloading column's markup:

[ASPx]
<dx:GridViewDataColumnCaption="Doc"VisibleIndex="5"><DataItemTemplate><dx:ASPxButtonID="ASPxButton1"runat="server"OnInit="ASPxButton1_Init"AutoPostBack="False"RenderMode="Link"Text="Download"><ImageIconID="actions_download_16x16"/></dx:ASPxButton></DataItemTemplate></dx:GridViewDataColumn>

Note that we are using the common GridViewDataColumn Class with the ASPxButton Class which ASPxButton.RenderMode Property has the Link value (see also: ASPxButton - How to disable default appearance starting with 13.2 (display only an image)). This way, we can display an image. If you need only a link, it is sufficient to use the GridViewDataHyperLinkColumn Class. The ASPxButton's client-side Click event code is calculated dynamically in the server-side Init event handler. Here we redirect a web browser to the FileDownloadHandler.asxh handler (e.g., see ASP.NET Futures - Generating Dynamic Images with HttpHandlers gets Easier - Scott Hanselman) to obtain the corresponding file by a row key value and send this file to the browser.

NOTE: If you are only interested in end-user capabilities for file uploading and downloading, consider using our ASPxFileManager Class (e.g., see File Download).

GridView - How to show LoadingPanel during export

$
0
0

When you export a grid with a lage amount of data, you might want to show the LoadingPanel during exporting. To do so, handle the button's client-side Click event to:

1) Show the loading panel;

2) Perform an ajax request to the server to export the grid;

3) Hide the loading panel on success and submit the form to attach the exported document to the response.

[JScript]
function OnClick(s, e){ $.ajax({ url: "Home/CallbackExport", type: "POST", data: GetFormData(), contentType: false, processData: false, beforeSend: (function(data){ LoadingPanel.Show();})}).done(function(data){ LoadingPanel.Hide(); $("#form").submit();});}

Note that in order to export the grid's state to the document, it is necessary to manually send the form data to the server during the ajax request:

[JScript]
... data: GetFormData(),...function GetFormData(){var fd = new FormData();var data = $('form').serializeArray(); $.each(data, function(key, input){ fd.append(input.name, input.value);});return fd;}

See Also:
How to show ASPxLoadingPanel during export

How to show ASPxLoadingPanel during export

$
0
0

When you export a grid with a lage amount of data, you might want to show the ASPxLoadingPanel during exporting. Generally, it is possible to show the LoadingPanel when you start the exporting process. However, you will not be able to determine the moment when it should be hidden, since none of events are generated at the client side when the exporting result is shown...

This example illustrates how to overcome this limit by using the asp:UpdatePanel. To get the desired result, we've used the Sys.WebForms.PageRequestManager Class. The Sys.WebForms.PageRequestManager endRequest event is raised after an asynchronous postback is finished and the control has been returned to the browser. Therefore, it is possible to hide the LoadingPanel in the endRequest event handler. However, when an export button inside the asp:UpdatePane is being clicked, its postback is transformed in an ajax callback. The problem is that when you use ajax you can't continue using the Response.Write, because Ajax doesn't write the entire page, but only some of its parts. So, it is necessary to keep data exported to a stream in the Session. Then you can send a postback to the server side and show the save dialog without ajax.

Note: If ASPxGridView exports data for more than 90 seconds, it is necessary to increase the value of the ScriptManager.AsyncPostBackTimeout property. This allows you to avoid the "The server request timed out" error during export.

See Also:
How to use the ASPxLoadingPanel as a progress indicator for AJAX UpdatePanel
GridView - How to show LoadingPanel during export

Example Comments

Added By: Don Krasnick at: 4/8/2013 12:26:36 PM    

Is there a way to do this in MVC? I get a Javascript error "Sys is not defined", presumably because this is part of ASPx controls and isn't normally available in an MVC solution.

Added By: Don Krasnick at: 4/8/2013 12:35:29 PM    

I'm actually looking for any MVC solution for those cases when a long-running export (PDF or CSV) is on-going so that the user realizes that they have to wait a while and won't try to hit the "export" button a 2nd time - Loading panel, progres bar, etc.

Added By: Marion (DevExpress Support) at: 4/8/2013 11:22:43 PM    

There is no UpdatePanel extension. So, I am afraid there is no solution for MVC.

Added By: Satheesh Kumar R Karuppusamy at: 8/13/2013 3:20:46 AM    

We have implemented the same code but we are keeping Exporter in user control. and loading panel in the master page.
and after export the grid. still the loading panel not get hide.

Added By: Marion (DevExpress Support) at: 8/13/2013 6:41:21 AM    

@Satheesh Kumar,
I have opened a new thread for you. Let's continue our discussion in it:
http://www.devexpress.com/Support/Center/Question/Details/Q378619

Added By: Samuel Adranyi 2 at: 8/21/2013 12:09:38 PM    

This does not work when its in a usercontrol

Added By: Marion (DevExpress Support) at: 8/22/2013 1:55:40 AM    

@ Samuel,
We are going to answer your question in the context of the following thread:
http://www.devexpress.com/Support/Center/Question/Details/Q379048

OBSOLETE - How to show a specific view for some users

$
0
0

In this example it is demonstrated how to show a custom View against a role of the currently logged user. The custom views were created and customized in the application model for each role separately. For more convenience, the custom views have the name of the role in the Id attribute. There is also a controller that tracks showing views in the application and replaces the default view model with a custom view model found in the application model by the role name.

Viewing all 7205 articles
Browse latest View live


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