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

How to create complex custom controls (XRTreeList and XRGrid)

$
0
0

This example demonstrates how to create custom data-aware controls that have a complex structure. The example consists of two projects:
- DevExpress.XtraReports.CustomControls. Contains all classes and methods related to custom controls.
- CustomControlExample. This project is for testing the aforementioned custom controls. This project invokes End-User Report Designers and Print Previews for both controls.

Take special note of the following classes and methods when examining the CustomControls project:
1. XRTreeList and XRGrid. They are XRControl descendants and contain all required properties and methods related to their visual representation.
1.1. The XRControl.CreatePresenter method allows you to create different presenters for visualizing your control at runtime and design time.
1.2. The XRControl.WriteContentTo method generates the visual representation and passes it to the resulting document.
1.3. The XRControl.CollectAssociatedComponents method allows you to link external objects (data source information and other Component properties) to your control.
1.4. The XRControl.CopyDataProperties method is required to inform your control of how to clone data source related properties.
1.5. The XRControl.CreateCollectionItem method defines how to create new collection items in your control.
1.6. The XRControl.CreateStyles method is responsible for creating specific control styles.
1.7. The XRControl.CreateScripts method creates scripts specific for this control.

2. XRTreeListDesigner and XRGridDesigner. These classes describe the design-time behavior of corresponding controls.
2.1. The XRControlDesigner.GetFilteredProperties method determines what properties should be visible in the Property Grid.
2.2. The XRControlDesigner.RegisterActionLists method fills the XRControl smart tag with required actions.

3. XRTreeListRuntimePresenter and XRGridRuntimePresenter. These classes generate visual representation of your controls.
3.1. The XRControlPresenter.CreateBrick method creates a container brick for displaying the control content.
3.2. The XRControlPresenter.PutStateToBrick method generates inner content based on the current control state.


Important note: the VB.NET solution is for VS 2012 or newer, because it uses new operators that do not exist in VS 2010.

See also:
How to: Create a Numeric Label
How to: Create a Progress Bar Control

How to create custom shapes with custom connection points for the DiagramDesignerControl

$
0
0

The Diagram control supports a special language for defining shapes. The main element that contains shape description is ShapeTemplate. This element describes a shape contour and may contain several segments:
- Start. Specifies the start point
- Line. Defines a line with start and end points
- Arc. Defines an arc with start and end points
To specify connection points, use the ShapeTemplate.ConnectionPoints property.
Shapes may contain parameters. Parameters may be used to dynamically calculate an end point, row height and other properties. To specify parameters, use the ShapeTemplate.Parameters property

How to create a report dynamically in the ASP.NET MVC application

$
0
0

This example illustrates how to create a report dynamically in the ASP.NET MVC application.

See also:
How to use XtraReports in an ASP.NET MVC application
How to link the Document Viewer with an external Ribbon control

Question Comments

Added By: vkr at: 11/14/2013 7:37:25 AM    

Where are we assigning the report with data here ? I see creating a report and returning it only!!

Added By: saeed dalvand at: 12/4/2015 8:11:31 AM    

that not work for me in asp.net mvc
i can use xtrareport in devexpress Application mvc but no in mvc Asp.net application

Added By: Vasily (DevExpress Support) at: 12/4/2015 10:31:47 AM    

Hello Saeed,

To process your recent post more efficiently, I created a separate ticket on your behalf: T320953: XtraReport is not working in ASP.NET MVC Application. This ticket is currently in our processing queue. Our team will address it as soon as we have any updates.

How to create fully custom Role, User, Event, Resource classes for use with the Security (old) and Scheduler modules

$
0
0

This example demonstrates how to create fully custom classes for use in our Security Module (with the 'old' DevExpress.ExpressApp.Security.SecurityComplex component) and Schedule Module:
    - Activity is an analog of our standard Event class that is used to represent appointments in the Scheduler Control.
    - Employee is an analog of the standard User class, which also supports the IResource interface to use objects of this class as resources in our custom appointment above.
    - Group is an analog of our standard Role class
To enable these two custom security classes in your application set the RoleType and UserType properties for the SecurityComplex component within the Application Designer.

Additionally, the two popular filtering tasks are implemented: filtering appointments by the current logged employee and also filtering resources to show only those owned by the current logged employee.
This functionality is provided by the SchedulerActivityListViewControllerBase class and its descendants as follows:
   a. Administrator account (Sam, to log on, leave the Password field empty) sees all the resources and appointments in the root scheduler view.
   b. Non-Administrator account (John, to log on, leave the Password field empty) sees only his own resources and appointments in the root scheduler view.
   c. Both Administrator and Non-Administrator accounts see their own resources and appointments in the nested scheduler view.
You can use SchedulerActivityListViewControllerBase  and related controllers for study purposes, since they demonstrate the most common filtering scenarios in the scheduler view. If you do not need all this specific functionality, simply remove these controllers and create your own ones (perhaps based on the provided example code) that will do only your specific task. For example, the controllers from this example are not suitable in the nested scheduler view because you miss some part of the default Link/Unlink functionality since the scheduler view is always filtered to show only its own resources and appointments.That may not be desired because you may want to have the capability to link appointments from other resources, but they won't be shown due to the above. Plus, these demo controllers are unnecessary for appointments filtering in the nested scheduler view, because by default, in this view only appointments from the current resources are shown.

Important notes

1. Example implementations are NOT designed for the 'new' security system components and scenarios (e.g., middle-tier application server or SecuredObjectSpaceProvider). To use the SecurityStrategyComplex component, provide fully custom implementations of the user and role classes as per the eXpressApp Framework > Task-Based Help > How to: Implement a Custom Security System User Based on an Existing Business Class article.

2. The Activity (appointment) and Employee (resource) classes' code was once created based on the code of the default Event and Resource classes from our DevExpress.Persistent.BaseImpl library. It may be necessary to update their code based on the source ...\XAF\DevExpress.Persistent\DevExpress.Persistent.BaseImpl\ library sources according to changes made in the latest XAF versions.

Question Comments

Added By: Ad de Rijke at: 5/19/2014 4:52:28 AM    

The Web project does not compile: 'The type or namespace name 'WinWebSolutionAspNetApplication' could not be found (are you missing a using directive or an assembly reference?)'

Added By: Dennis (DevExpress Support) at: 5/20/2014 3:31:16 AM    @Ad: For some reason the WebApplication.cs file was emptied. I have attached a working sample for your reference. I will also update this example as well.Added By: Ville Virtanen at: 12/4/2015 11:06:39 PM    

When trying to run it gives an error: Another rule with ID = 'EventIntervalValid' already exists.

When I commented following lines, it worked, but how I disable the BaseImpl rule?

//[NonPersistent]
       //[Browsable(false)]
       //[RuleFromBoolProperty("EventIntervalValid", DefaultContexts.Save, "The start date must be less than the end date", SkipNullOrEmptyValues = false, UsedProperties = "StartOn, EndOn")]
       //public bool IsIntervalValid { get { return StartOn <= EndOn; } }

How to share one RichEditControl toolbar between several RichEditControls

$
0
0

Let us assume that we have created a simple rich text editor with a toolbar interface (see How to: Create a Simple Word Processor with Bar Menu and How to: Create a Simple Word Processor with Ribbon Menu help sections). Now, if you want to reuse RichEditControl UI for several RichEditControls on the form, do the following:

1) Detach the original RichEditControl from the RichEditBarController.RichEditControl property at design time in the VS Property Grid.
2) Handle the RichEditControl.Enter event for all RichEditControls on the form and assign the source RichEditControl to the RichEditBarController.RichEditControl property.

NOTE: If you want each RichEditControl to have its own UI, you can create a separate UserControl with RichEditControl and its UI. Then, just add a required number of these UserControl instances to the form.

Question Comments

Added By: Andrey Kushnarev at: 12/5/2015 10:15:11 AM    

This does not work properly if RichEditControl has comments within it content

Adding report management functionality to an MVVM application

$
0
0
This example demonstrates how to use GridReportManagerService in conjunction with ReportManagerBehavior to provide the end-user with the ability to create and manage reports.

Report Storage for the End-User Report Designer (WPF beta)

$
0
0
The following example demonstrates how to implement a report storage to persist report definitions in a database or in any other custom location. This may be useful when providing end-users with the capability to create and customize reports using XtraReports End-User Designer if it is necessary to have a common target for saving and sharing all reports. At present, the aforementioned functionality is accomplished through the DevExpress.Xpf.Reports.UserDesigner.IReportFileStorage interface. The interface provides the following methods:
- ShowSaveAsDialog
- ShowOpenDialog
- Load
- Save
- GetErrorMessage
As we see, the interface methods are quite straightforward: the first two methods are intended to show a dialog to an end-user where he can select a report among the predefined reports, or otherwise, save it; when he does that, the Save or Load methods are invoked with the unique name of the selected report. That's where you should implement your custom save logic. If you're unfamiliar with this procedure, please refer to the original E2704 example, which provides additional information in this regard (the example illustrates the same technique but for WinForms EUD)
NOTE:
The WPF Report EUD is still in the beta stage (v.15.1); thus, there can be some limitations which are impossible to overcome at this moment (for example, there is no way to fill the SubReport's ReportSource drop-down window with the list of available reports). Moreover, some detail implementation may be changed on its official release. If you're experiencing any issues with running this sample or have additional questions, please contact our Support Team directly for further assistance.
[v15.2 History changes]
The IReportFileStorage interface has been renamed to IReportStorage

XtraEditors Library - How to change the border color of an editor assigned to Bar or Ribbon if the editor is in the Hot state and the BorderStyle property is set to UltraFlat

$
0
0
This example illustrates how to change the border color of an editor if editor is assigned to Bar or Ribbon and the editor's BorderStyle property is set to UltraFlat

OBSOLETE - ASPxGridView - How to display a truncated text in a column

$
0
0

UPDATED:

Starting with version v2015 vol 2 (v15.2), this functionality is available out of the box. Simply set the ASPxGridView.SettingsBehavior.AllowEllipsisInTextGridViewDataColumn.Settings.AllowEllipsisInText property to True to activate it. Please refer to the ASP.NET Grid View - Data Range Filter, Adaptivity and More (Coming soon in v15.2) blog post and the Text Ellipsis demo for more information.
If you have version v15.2+ available, consider using the built-in functionality instead of the approach detailed below.

This example demonstrates how to display a truncated text in ASPxGridView column and show a full value as the tool tip.
1) Handle the ASPxGridView.CustomColumnDisplayText event to truncate displayed text in DataCell via the e.DisplayText property;
2) Handle the ASPxGridView.HtmlDataCellPrepared event to set tool tips for the same DataCell via the e.Cell.ToolTip property.

See Also:
E3935: ASPxTreeList - How to display a truncated text in a column
ASPxGridView - How to display truncated text in a resizable column (using CSS)

Question Comments

Added By: John Daren Dizon 1 at: 11/6/2015 5:37:40 PM    

how to set this for all the columns in the grid?

Added By: Larry (DevExpress Support) at: 11/9/2015 4:56:51 AM    

Hello,

To process your recent post more efficiently, I created a separate ticket on your behalf: T309640: ASPxGridView - How to display a truncated text for all columns. This ticket is currently in our processing queue. Our team will address it as soon as we have any updates.

OBSOLETE - ASPxGridView - How to display truncated text in a resizable column (using CSS)

$
0
0

UPDATED:

Starting with version v2015 vol 2 (v15.2), this functionality is available out of the box. Simply set the ASPxGridView.SettingsBehavior.AllowEllipsisInTextGridViewDataColumn.Settings.AllowEllipsisInText property to True to activate it. Please refer to the ASP.NET Grid View - Data Range Filter, Adaptivity and More (Coming soon in v15.2) blog post and the Text Ellipsis demo for more information.
If you have version v15.2+ available, consider using the built-in functionality instead of the approach detailed below.

This example demonstrates how to display truncated text in a resizable ASPxGridView column and show a full value as a tool tip.

1) Apply the following CSS class to column cells:


[CSS]
.truncated{white-space:nowrap;overflow:hidden;text-overflow:ellipsis;}
[ASPx]
<dx:GridViewDataTextColumnFieldName="Description"VisibleIndex="2"><CellStyleCssClass="truncated"></CellStyle></dx:GridViewDataTextColumn>


2) Handle the ASPxGridView.HtmlDataCellPrepared event to set tool tips for the same DataCell via the e.Cell.ToolTip property.

See Also:
ASPxGridView - How to display a truncated text in a column

OBSOLETE - ASPxTreeList - How to display a truncated text in a column

$
0
0

UPDATED:

Starting with version v2015 vol 2 (v15.2), this functionality is available out of the box. Simply set the ASPxTreeList.SettingsBehavior.AllowEllipsisInText / TreeListDataColumn.AllowEllipsisInText property to True to activate it. Please refer to the ASP.NET Grid View - Data Range Filter, Adaptivity and More (Coming soon in v15.2) blog post and the Resizing Columns demo for more information.
If you have version v15.2+ available, consider using the built-in functionality instead of the approach detailed below.

This example demonstrates how to display a truncated text in the ASPxTreeList column and show a full value as a tooltip.
1) Handle the ASPxTreeList.HtmlDataCellPrepared event and truncate the displayed text in DataCell via the e.Cell.Text property;
2) Set a tooltip for the same DataCell via the e.Cell.ToolTip property.

See Also: 
E3934: ASPxGridView - How to display a truncated text in a column

A master-detail grid with Entity Framework objects

$
0
0

Starting with version 2012 vol 1, it is possible to enable the master-detail feature for collection properties generated by Entity Framework. See the Use Master-detail views with generic collections of type IList<T> and IEnumerable thread for details.

This example demonstrates how to bind related entities to the XtraGrid and display them in master-detail views.

See also:How to display Entity Framework objects in a grid within master-detail mode when entities have many-to-many relationship and a linked table is included to an entity model

Question Comments

Added By: Josh Soriano at: 8/16/2013 5:53:31 PM    

my problem is im using EF5 which preferred using DbSet instead of ObjectQuery, and how can i add a row in child grid...

Added By: Hassan Gulzar at: 2/1/2015 5:30:13 AM    

Same issue here as Josh said above. EF5 and onwards, the line gridControl1.DataSource = new BindingSource(customersQuery, ""); becomes invalid as customersQuery needs to have a .ToList() and that defeats the purpose because 1) I cannot have the CRUD ops auto reflect on the context 2) I cannot have one save button to submit all the changes.

Added By: Nikita (DevExpress Support) at: 2/2/2015 12:21:40 AM    

Hello Hassan,
We have a separate How to implement CRUD operations when Entity Framework 5 is used example that illustrates how to use Master-Detail mode. I see that you have published a comment about an issue that occurs when using the approach suggested in that ticket. We will post an answer to your inquiry shortly. 

Added By: Yasin Türk 1 at: 12/7/2015 4:28:31 AM    

how can i design childlist gridview.. column names, field names etc

Added By: Nikita (DevExpress Support) at: 12/7/2015 7:50:36 AM    

Hello,
You can use the common approach described in the Detail Pattern and Clone Views. In this case, the relation name of the pattern view should equal to the name of the related navigation property in the entity model.

How to implement conditional formatting for cells

$
0
0

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

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

Update: Starting with version 14.1, there is no need to create custom styles. Instead, you can use the built-in Conditional Formatting mechanism to color cells. 

Question Comments

Added By: Zhigeng Fan at: 12/7/2015 6:58:02 AM    

how to do conditional formatting on all cells regardless of columns? I want to gray all cells where the value is null

Added By: Alexander Rus (DevExpress Support) at: 12/7/2015 9:58:20 AM    

Hello Zhigeng,
To process your recent post more efficiently, I created a separate ticket on your behalf: T321646: How to apply the same formatting rule to all columns

Thanks,
Alexander

How to serialize DockLayoutManager when TabbedDocumentUIService is used

$
0
0

Some of DockLayoutManager’s panel groups can contain documents that were created from ViewModel with IDocumentManagerService. To serialize and restore them correctly, it is necessary to perform these steps:

1. Create a style and set a name for DocumentPanel. To do this, bind DocumentPanel.BindableName to a unique property.

2. Apply this style to all documents that will be created from ViewModel.

3. Before serializing DockLayoutManager, serialize all documents created from ViewModel.

4. Before restoring DockLayoutManager, recreate all documents created from ViewModel.

Custom XtraTabbedMdiManager - How to add a button showing MDI child windows list to the XtraTabbedMdiManager's header

$
0
0

This sample shows how to add a button showing MDI child windows list to the XtraTabbedMdiManager's header. A button like "Active Files" in Visual Studio. To accomplish this, we've created an XtraTabbedMdiManager descendant along with descendants of other classes like the TabHeaderViewInfo and TabButtonsPanel. Also, since we cannot make changes to the Enums, we cannot extend the buttons set available in the HeaderButtons property. So, a separate property controlling this button's visibility has been added - HeaderShowActiveFilesButton. It has the bool type and by default is set to false.

Question Comments

Added By: Mike Liu at: 11/1/2013 11:35:55 AM    

Hi I downloaded this example, and ran it, but I didn't see the button on the tab manager header. Where is the button?

Added By: JJDX at: 9/21/2014 11:12:23 AM    

Same here, dl, run but no buttons, i search for HeaderShowActiveFilesButton , change it to true but there is no button still.

Added By: Yaroslav (DevExpress Support) at: 9/22/2014 6:24:58 AM    

Hi Roman,
This example was created long time ago, so some internal methods have been changed since that time. I slightly updated the target project (both C# and VB.NET versions) in order to fix the aforementioned issue. Now an additional button is displayed as expected under the latest 14.1 version.
Don't hesitate to contact us in case of any difficulty. 

Added By: Christian Tüber at: 12/7/2015 11:50:34 PM    

I modified the example to have a feature toggle button. I set a super tool tip for the EditorButton but it is not shown.
Do i have to assign it to the RibbonControl on the XtraForm to get it running?

Here my code example:
     protected override TabButtonInfo CreateButton(TabButtonType button)
     {
        if ( button == TabButtonType.User )
        {
            ButtonPredefines predefine = ButtonPredefines.Glyph;
               Boolean selectedPageIsAFavorite = false;
               if (this.TabViewInfo.SelectedTabPage != null && this.TabViewInfo.SelectedTabPage is XtraMdiTabPage)
               {
                   XtraMdiTabPage mdiTabPage = (XtraMdiTabPage)this.TabViewInfo.SelectedTabPage;
                   if (    mdiTabPage.MdiChild != null &&
                           mdiTabPage.MdiChild.ParentForm != null &&
                           mdiTabPage.MdiChild.ParentForm is MainForm)
                   selectedPageIsAFavorite = ((MainForm)mdiTabPage.MdiChild.ParentForm).IsSelectedPageAFavorite((Form)mdiTabPage.MdiChild);
               }
               SuperToolTip superToolTipForFavoriteToggleButton = new SuperToolTip();
               SuperToolTipSetupArgs args = new SuperToolTipSetupArgs();
               args.Title.Text = "Favorit setzen/löschen";
               Image favoriteGlyph = null;

               if (selectedPageIsAFavorite)
               {
                   // page is a favorite
                   args.Contents.Text = "Anklicken zum Löschen des Favoritenstatus";
                   favoriteGlyph = Properties.Resources.ov_favorite_active;
               }
               else
               {
                   // page is NOT a favorite
                   args.Contents.Text = "Anklicken zum Setzen des Favoritenstatus";
                   favoriteGlyph = Properties.Resources.ov_favorite_non_active;
               }

               superToolTipForFavoriteToggleButton.Setup(args);
               EditorButton favoriteButton = new EditorButton(predefine, favoriteGlyph, superToolTipForFavoriteToggleButton);
               TabButtonInfo tabBtn = new TabButtonInfo(favoriteButton, button);
           return tabBtn;
        }

        return base.CreateButton(button);
     }


How to bind a GridControl to a DataTable

How to print DetailBand a particular amount of times irregardless of the number of records in a report datasource

$
0
0

Sometimes, it is necessary to print a detail section a particular number of times even if the underlying DataSource contains a less number of records. The current version of XtraReports does not allow one to print this section more times than the number of records.

As a solution for this task, you can clear the report's DataSource and DataMember properties, set the DetailPrintCountOnEmptyDataSource property to the necessary number, and then populate the detail section data manually using the DetailBand's BeforePrint event.

This example demonstrates this approach in action.

See also:
How to repeat the Detail report band multiple times (a data-bound report)

How to repeat the Detail report band multiple times (a data-bound report)

$
0
0
If a report is unbound, you can specify how many times the Detail band content is printed through the XtraReport.PrintOptions.DetailCountOnEmptyDataSource property.

If a report is data bound, you can limit the number of times the Detail band is printed by using the DetailCount property.

Please note that the DetailCount property is designed to specify the maximum number (i.e., the limit) of times the Detail band is printed. In other words, if a data source contains one record, we cannot print it more than one time by using the DetailCount property.
We need to use the solution illustrated by this example. It demonstrates how to repeat a data source record depending on a value taken from another field. To achieve this, add an unbound DetailReportBand and control the number of copies using its ReportPrintOptions.DetailCountOnEmptyDataSource property.

See also: 
How to print DetailBand a particular amount of times irregardless of the number of records in a report datasource

How to change the current NavigationPane behavior to make it look like "hamburger menu" from mobile applications

$
0
0

The "hamburger menu" is a popular menu control for modern mobile applications. We have NavigationPane whose layout looks similar to this "hamburger menu", but has several differences. So, this example demonstrates how to customize the current NavigationPane behavior to make it look like the mentioned menu for modern mobile applications.

WPF Report Designer (Beta) - How to hide a property in the Properties window

$
0
0
This example demonstrates how to hide the "DataSource", "DataMember", and "DataAdapter" properties in the Properties window.

First, get the Property Grid from the visual tree. I completed this by using the LayoutTreeHelper class. Then, get a property definition instance from the PropertyGridControl.PropertyDefinitions collection and set PropertyDefinitionBase.Visibility to Collapsed to hide a property.
Here are some points regarding how to get a property from the PropertyGridControl.PropertyDefinitions collection. Some properties are determined by the PropertyDefinitionBase.Path property (for instance, the "DataSource" and "PrinterName" properties). To hide them, compare the PropertyDefinitionBase.Path property value with the string value (e.g. "DataSource") to get a property object from PropertyGridControl.PropertyDefinitions.
Other properties are determined by the type. To hide them, create a brand new PropertyDefinitionBase object (set up its Path as required) and add it to the PropertyGridControl.PropertyDefinitions.

WinForms: WinForms End-User Report Designer - How to hide a property in the Properties window
Viewing all 7205 articles
Browse latest View live


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