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

DiagramControl - How to create custom shapes with connection points

$
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.
To register custom shapes, use the DiagramToolboxRegistrator.RegisterShapes method.
Question Comments

Added By: Piotr Migdalski 1 at: 1/15/2016 7:12:33 AM    

Hello,

Is possible to use in templates images (from resources)?

Added By: Alexander Ch (DevExpress Support) at: 1/18/2016 4:45:20 AM    Hi Piotr,

ShapeTemplates allow you to describe a shape using primitives like Line and Arc. Displaying an image in a shape is a separate feature, which we plan to introduce in future versions.

Thanks,
AlexAdded By: Craig Dunstan at: 4/3/2016 7:05:49 AM    Is there any ability to leverage Visio stencils - either by converting them directly or via an intermediary like SVG?

ASPxGridListEditor - Reference properties editing in the batch mode

WinForms End-User Designer - How to customize the Smart Tag menu of a control

$
0
0

This example demonstrates how to customize the XRLabel's Smart Tag menu to make the following properties available: TextData Binding (the Text property)WidthFHeightFLocationF.XLocationF.Y.
To achieve this, we do the following:
1. Implement a DevExpress.XtraReports.Design.XRControlDesigner descendant and override XRControlDesigner.RegisterActionLists to provide a custom action list.
2. Create a custom report control by subclassing a required control (Creating Custom Controls) and register the custom control on the toolbox by using the design-time IToolboxService service. 
For more information on adding custom controls to the Toolbox and removing standard ones from it, check the following articles:
How to: Register a Custom Control in the End-User Designer's Toolbox.
How to: Make a Custom Control be Available Only for a Specific Report Instance 
3. Link this designer to the custom XRControl by using the XRDesigner attribute. 

See also:
How to create custom report controls
How to programatically invoke the smart tag once an XRControl is added to report in the WinForms End-User Designer
How to remove the ReportSource property from a smart tag menu of the XRSubreport control

How to provide an event that is raised on changing a grid layout

$
0
0

This example demonstrates how to provide an event that is raised as soon as a grid layout is changed.


In this example, we have created a GridLayoutHelper class that handles changes of the GridControl object's necessary properties and columns, and raises a custom event in its handlers.


This class can be easily attached to the GridControl object in the following manner:

[XAML]
<dxg:GridControlx:Name="grid"AutoPopulateColumns="True"><dxmvvm:Interaction.Behaviors><local:GridLayoutHelperLayoutChanged="OnGridLayoutChanged"/></dxmvvm:Interaction.Behaviors></dxg:GridControl>

 

To learn more on how to implement similar functionality in Silverlight, refer to the T243422 example.

Question Comments

Added By: bruno mandarà at: 4/4/2016 5:10:10 AM    not work, the change events, are only triggered for the last columnAdded By: Andrey K (DevExpress Support) at: 4/4/2016 6:13:35 AM    Thank you for the report. I will describe the cause of the issue and provide a solution in the T363569: How to subscribe to events of all GridControl columns thread. I will fix the current example as well.

Thanks,
Andrey

How to calculate Total cell values based on the low level Cell summary values

$
0
0

This example demonstrates how to use the CustomSummary Event to resolve the problem described in the Total values calculation seems to be incorrect, how to calculate Min, Max, Average values based on the cell thread. The sample is built based on the ASPxPivotGrid control, but it is also possible to use this approach with other pivot control for WinForms, WPF, Silverlight and MVC. 
Below is the CustomSummary event handler code description:
1. In the root IF clause, we determine the required summary type. For all fields below the "Company" one, it is necessary to show min values. In the attached sample project, all fields are located in the Row Area, so it is enough to check the AreaIndex Property of the corresponding e.RowField:

[C#]
if(e.RowField!=null&&e.RowField.AreaIndex>=fieldCompanyName.AreaIndex){//Min}else{//Sum of Min}

2. Pivot Grid automatically calculates predefined summary values for all cells, so it is not necessary to recalculate them manually. You can get them from the e.SummaryValue object and assign them to the CustomValue Property:

[C#]
e.CustomValue=e.SummaryValue.Min;

3. Now it is necessary to calculate custom summary values (Sum of Min). Pivot Grid calculates summary values for all cells based on the underlying data source rows regardless the cell type. However, for our task it is necessary to calculate total values based on the low level cells summary values. E.g for Quarter rows it is necessary to group data by Company, then find Min value in each group and finally summarize all min values. For Year field logic will be the same but it is necessary to group data by Quarter and Company. For Grand Total cell it is necessary to group data by Year, Quarter and Company. This is a rather complex task so it is better to discuss the code part by part.

3.1. To get grouping fields simply iterates through the Fields collection and find field that are located into the Row Area below the current e.RowField but above the Company field:

[C#]
vargroupingFields=pivot.Fields.Cast<PivotGridField>().Where(f=>f.Visible&&f.Area==fieldCompanyName.Area&&f.AreaIndex<=fieldCompanyName.AreaIndex&&(e.RowField==null||f.AreaIndex>e.RowField.AreaIndex));

 3.2. Get the pivot drill-down data source and cast it to the IEnumerable<PivotDrillDownDataRow> type:

[C#]
vardrillDownDataSource=e.CreateDrillDownDataSource().Cast<PivotDrillDownDataRow>();

3.3. At present, we have a single collection of data source rows. To create a collection of row groups, execute the following code:

[C#]
List<IEnumerable<PivotDrillDownDataRow>>temporaryList=newList<IEnumerable<PivotDrillDownDataRow>>();temporaryList.Add(drillDownDataSource);IEnumerable<IEnumerable<PivotDrillDownDataRow>>dataGroups=temporaryList;

3.4. Now it is necessary to group the entire data source by groupingFields requested earlier:

[C#]
foreach(varfieldingroupingFields){   varlocalField=field;   dataGroups=dataGroups.SelectMany(groupRows=>groupRows.GroupBy(r=>r[localField]).Select(g=>g.AsEnumerable()));}

3.5. The final step is to iterate through all groups, find a min value in each of them and then calculate the sum of all found values:

[C#]
varvalue=dataGroups.Sum(groupRows=>groupRows.Min(r=>Convert.ToDecimal(r[e.FieldName])));e.CustomValue=value;

How to obtain a dashboard item's client data in the WinForms Viewer

$
0
0

The following example demonstrates how to get client data corresponding to a particular visual element using DashboardViewer's API.
In this example, the DashboardViewer.DashboardItemClick event is handled to obtain client data for the Card dashboard item and display this data in a Chart control. We obtain axis points placed on the "Sparkline" axis for the clicked card, determine corresponding actual/target values, and save these values to a data table. This table is used as a data source for the Chart control. 
Note that you can apply master filtering by year in the Pie dashboard item. The chart will display client data according to the selected year.

How to obtain a dashboard item's underlying data in the Web Viewer

$
0
0

The following example demonstrates how to get underlying data corresponding to a particular visual element using the ASPxClientDashboardViewer's API.

In this example, the ASPxClientDashboardViewer.ItemClick event is handled to obtain underlying data and invoke the dxPopup widget with the child dxDataGrid.

In the event handler, the RequestUnderlyingData method is called to obtain records from the dashboard's data source. The dxDataGrid is used to display these records.

How to use a GetSelectedFieldValues method to obtain values of several columns at once


ASPxGridView - Batch Editing - How to use external buttons to update data and enable them only when a row/cell has been changed

How to bind a report to a datasource, whose data is loaded from an XML file

$
0
0

This code sample illustrates how to bind a report to XML data stored in a file (Cars.xml in this case). 

How to create a Web Dashboard Designer application

$
0
0

This example shows how to create a Web Dashboard Designer application and provide data for dashboards.

The project contains a simple dashboard and three available data sources: the Excel, SQL (a local SQLite database) and OLAP data sources. You can use these data sources to create a new dashboard. To learn how to create a Web Designer application from scratch, see the following topic: Creating a Dashboard using a Web Designer.

Note that the OLAP data source requires the ADOMD.NET data provider installed on the web server. You can get the latest version of this provider here: https://www.microsoft.com/en-us/download/details.aspx?id=42295.
To be able to use the SQLite data source, build the project before running to download the ADO.NET provider for SQLite automatically.

How to obtain the SQL string that has been automatically constructed for a table query

$
0
0

This example illustrates how to obtain the query string that is used to fetch data from the connected data source. Prior to obtaining the query string, open the corresponding data connection by calling the SqlDataConnection.Open method.

How to create a DiagramShape descendant and serialize its properties

$
0
0
This example demonstrates how to serialize custom data using DiagramControl's serialization mechanism. In the example, the Content property of diagram shapes is loaded from data objects every time the diagram is shown. To associate shapes with data objects, the DatabaseObjectID property is added at the DiagramShape descendant level. To serialize this property along with standard DiagramShape properties, perform the following steps:

Note:
In certain scenarios, it is easier to use the DiagramShape.Tag property to store custom data without creating DiagramShape descendants. In this case, no further steps are needed as the Tag property is serialized by default.

1) Mark your custom property with the XtraSerializableProperty attribute:
[C#]
[Browsable(false),XtraSerializableProperty]publicintDatabaseObjectID{get;set;}
Set the Browsable(false) attribute if you don't want to display your custom property in DiagramControl's property editor.

2) Call the ItemTypeRegistrator.Register method to register your custom shape type for serialization:
[C#]
DiagramControl.ItemTypeRegistrator.Register(typeof(DiagramShapeEx));

SqlDataSource - How to use ExpressionEvaluator to programmatically filter report data

$
0
0
This example demonstrates how to use the DevExpress.Data.Filtering.Helpers.ExpressionEvaluator.Fit method to programmatically filter the SqlDataSource query. The Fit operation result is used in the band's BeforePrint event handler to allow or cancel rendering of the band content through the e.Cancel property. Please note that the filter expression should be construct according to the Criteria Language Syntax.

Other examples of using DevExpress.Data.Filtering.Helpers.ExpressionEvaluator appear here:
How to get one calculated field value in the other calculated field's GetResult event handler by using ExpressionEvaluator
How to evaluate the calculated field expression
First and last column value

How to display a login view as a popup window during navigation between views

$
0
0

Starting with 14.2, please use this example.
This approach can be applied starting with 13.2.9. 

This example demonstrates how to check whether the user is logged in and display a login view when it is necessary during navigation.

It is necessary to perform the following steps to accomplish this task:

1. Add a new view and place a dxPopup in it.

2. Implement the required logic for this view in a corresponding view model.

3. Handle the HtmlApplication.initialized event. In this event handler, get the login view template using the HtmlApplication.getViewTemplate method and add the view to the view port. This will allow you to display its internal popup using options from its view model.

4. Bind the login view model to the view markup using Knockout.

5. Declare a global variable for determining when a user is logged in. In this example we set this option to false by default, and we will set it to true when a user is logged in. This variable can be accessed from any part of the application and we can change its value in the login view model.

6. Handle the HtmlApplication.navigating event. In this event handler, we can get a view info (see HtmlApplication.getViewTemplateInfo) for the navigated view and check user credentials if necessary. For this purpose, we added the secure option to those views that should not be displayed for unauthorized users. If the user unauthorized, we can call a method from the login view model to display dxPopup from the login view. Moreover, you can cancel navigation by setting the cancel parameter of the event handler to true.

See also:
How to send authenticated requests to the OData service

Question Comments

Added By: Alexandre Henriques at: 4/28/2014 7:36:44 AM    

How do I make this piece of code in version 13.2.7?

app.initialized.add(function() {
       var $view = app.getViewTemplate("LogOnPopup");
       $view.appendTo(".dx-viewport");
       LogOnAsPopupView.loggedOn = ko.observable(false);
       LogOnAsPopupView.logOnPopupViewModel = LogOnAsPopupView.LogOnPopup();
       ko.applyBindings(LogOnAsPopupView.logOnPopupViewModel, $view[0]);
   });

Added By: Nikolai (DevExpress Support) at: 4/28/2014 11:00:20 PM    Hi Alexandre,

I have created a separate ticket for this issue. Please post comments to the How to display a login view as a popup window during navigation between views (13.2.7) ticket.Added By: Faraz Faheem at: 6/1/2014 3:28:54 AM    

Im having error on initialized event. Error says 'Error: cannot ready property 'add' of undefined' on app.initialized.add(funtion() { line.

Please help me

Added By: Faraz Faheem at: 6/1/2014 3:52:38 AM    

I just upgraded my project to 13.2.9 by project converter and viola everything works.

Thanks for the self-explanatory post.

Added By: Nikolai (DevExpress Support) at: 6/2/2014 12:15:33 AM    You are always welcome, Faraz.Added By: Faraz Faheem at: 6/3/2014 7:56:19 AM    

Hi Nikolai,

With authentication implementation, my LogOn.js file looks like below
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
AESalesApp.LogOnPopup = function (params) {

   var viewModel = {
       userid: ko.observable(""),
       password: ko.observable(""),
       visible: ko.observable(false),
       authenticated: ko.observable(false),
       redirectParam: this.redirectParams,
       logOn: function () {

           var user = {
               Name: this.userid(),
               UserName: this.userid()
           };
        
           AESalesApp.UserDb.authenticateUser(user).done(function (data) {

               AESalesApp.loggedOn(true);

               AESalesApp.credentialStore.insert({
                id: 1,
                accessToken: "34234234234234234",
                expiry: 234,
                refreshToken: "134234234234234",
                name: "faraz"
                });

               if (viewModel.redirectParam) {
                   AESalesApp.app.navigate(viewModel.redirectParam.uri, viewModel.redirectParam.options);
               }
               viewModel.close();

           });
       
       },
       show: function (redirectParams) {
           viewModel.visible(true);
           viewModel.redirectParam = redirectParams;
       },
       close: function () {
           viewModel.visible(false);
           delete viewModel.redirectParam;
       }
   };

   return viewModel;
};
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
where:
AESalesApp.UserDb is CustomStore getting data from Web Api. It is working fine and data is coming back from authenticalUser call.

I am having 2 problems here.
1. Done function param 'data' is not getting results from authenticateUser function  
2. Popup is not closing down

Added By: Nikolai (DevExpress Support) at: 6/4/2014 2:40:03 AM    Hi Faraz,

I have created a separate ticket for this issue. Please post all comments in the How to implement authentication with a popup login viewAdded By: Jerther at: 11/28/2014 2:08:30 PM    

this line should be updated:

<div data-bind="dxTextBox:{ type: 'password', value: password }"></div>

with

<div data-bind="dxTextBox:{ mode: 'password', value: password }"></div>

Added By: Nikolai (DevExpress Support) at: 12/1/2014 3:52:34 AM    Hi Jerther,

Thank you for bringing this to our attention. I've updated this example.Added By: V.Mangione at: 12/4/2014 7:55:59 AM    

Hi, this sample doesn't appear to be working anymore on just released v 14.2.3
The popup stays hidden.

Added By: Nikolai (DevExpress Support) at: 12/5/2014 2:23:56 AM    Hi,

Starting with 14.2, please use this example.Added By: IMiron at: 10/9/2015 2:06:22 PM    

Hi,

Can you please tell me how this can be accomplished with the Angular approach?
A sample would be best.

Thanks,
Ionut.

Added By: Nikolai (DevExpress Support) at: 10/12/2015 1:38:07 AM    Hello IMiron,

The DevExtreme framework is based on KnockoutJS and jQuery. AngularJS has its own navigation mechanism. I suggest that you refer to Angular documentation and forums regarding this issue.

See also:
ngView
Routing & Multiple ViewsAdded By: Julian Leung at: 4/6/2016 9:07:30 PM    I am using this login sample, but I got some problems when I change the dxList to dxDataGrid. I seems that the problem come from data source, it cannot get the data from it.

        <div data-bind="dxDataGrid: { dataSource: dataSource,                 columns: [                    { dataField: 'ItemCode'},                    { dataField: 'BatchNum'},                      ] 

                  }">


var dataSource = {    store: new DevExpress.data.CustomStore({        load: function () {            return $.getJSON('http://localhost:55960/DataService.svc/efSeason');        }    })}


Added By: Nikolai (DevExpress Support) at: 4/7/2016 3:55:00 AM    

Hello Julian,

To process your recent post more efficiently, I created a separate ticket on your behalf: T365094: dxDataGrid - Ho to implement a custom data source. This ticket is currently in our processing queue. Our team will address it as soon as we have any updates.


dxFileUploader - How to upload files to the server in an ASP.NET Web Forms application

dxFileUploader - How to upload files to the server in an ASP.NET MVC application

How to enable Drag and Drop feature in the TableView

$
0
0

This example shows how to enable Drag and Drop functionality in the TableView.

Please note that if you wish to enable this functionality, it is necessary to add a reference to the DevExpress.Xpf.Grid.Extensions assembly.

How to redirect hyperlinks within an exported PDF document

$
0
0

This example demonstrates how to implement the DevExpress.XtraRichEdit.Services.IPdfLinkUpdater interface to redirect hyperlinks within an exported PDF document. In particular, this example merges two HTML files containing cross references into a single PDF document and updates external hyperlinks so that they point to bookmarks within the document.


Starting from 15.2.9:
The IPdfLinkUpdater interface has been renamed to ILinkUpdater and its functionality has been extended to include the ResolveBookmarkTitle method, which allows you to change the titles used to display document bookmarks in the Bookmarks panel of a PDF Viewer after the document is exported to PDF.

How to connect to a remote data service instead of using a direct database connection

$
0
0

Scenario

In this example, we will create a WCF IDataStore service that will be used by our client (Console Application) as a data layer. Instead of the direct connection to the database, our client will connect to a remote service, which is way more secure and thus important in many enterprise scenarios as database connection settings are not exposed to the client.


Steps to implement

1. Create a new WCF Service Application project and add references to the DevExpress.Data and DevExpress.Xpo assemblies and remove files with auto-generated interfaces for the service.

2. Modify the service class as shown in the Service1 file. This service initializes a connection provider and stores it in the static DataStore property, which is then used by the base DataStoreService class.

3. Change some binding properties as shown in the example's web.config file. At this stage, the service part is ready to work and we need to implement a client to consume data from our data store service (for demonstration purposes, we will create a Console Application).

4. Add the Console Application into the existing solution.

5. Add a new code file for a Customer class using the DevExpress v1X.X ORM Persistent Object item template. See a code of Customer class in the ConsoleApplication\Customer code file.

6. Pass the address of our service into the GetDataLayer method of the XpoDefault class. For this, modify the Main method of the Console Application as shown in the ConsoleApplication\Program code file. Please note that the port number in the connection string may be different. You can check it in the properties of the service project in the Solution Explorer:


As a result, we will see the following output:

Important notes
If you are using an XAF client, then in the simplest case, you can just set the XafApplication.ConnectionString to the address of your data store service (http://localhost:55777/Service1.svc). Refer to the Connect an XAF Application to a Database Provider help article for more details.

Troubleshooting
1. If WCF throws the "Request Entity Too Large" error, you can apply a standard solution from StackOverFlow: http://stackoverflow.com/questions/10122957/

2. If WCF throws the "The maximum string content length quota (8192) has been exceeded while reading XML data." error, you can extend bindings in the following manner as per http://stackoverflow.com/questions/6600057/the-maximum-string-content-length-quota-8192-has-been-exceeded-while-reading-x:

[XML]
<bindings><basicHttpBinding><bindingname="ServicesBinding"maxBufferPoolSize="2147483647"maxReceivedMessageSize="2147483647"maxBufferSize="2147483647"transferMode="Streamed"><readerQuotasmaxDepth="2147483647"maxArrayLength="2147483647"maxStringContentLength="2147483647"/></binding></basicHttpBinding></bindings>

 

See Also:
How to use XPO with a Web Service
Transferring Data via WCF Services
How to connect to a remote data service from a Silverlight application

How to create a data caching service that helps improve performance in distributed applications

How to implement a distributed object layer service working via WCF

How to connect to remote data store and configure WCF end point programmatically

 

Question Comments

Added By: NBT Developers at: 5/28/2014 10:39:32 AM    

FYI on this part "If you are using an XAF client, then in the simplest case, you can just set the XafApplication.ConnectionString to the address of your data store service (http://localhost:55777/Service1.svc). "

Literally do this:
WebApplication.Instance.ConnectionString = "http://localhost:55777/Service1.svc&quot;;

XpoDefault.DataLayer = XpoDefault.GetDataLayer("http://localhost:55777/Service1.svc&quot;,
           AutoCreateOption.DatabaseAndSchema);

           XpoDefault.Session = null;

           using (UnitOfWork uow = new UnitOfWork())
           {
           }

Added By: Jarkko Nieminen 1 at: 8/14/2015 5:38:07 AM    

I got the  "Entity is too large"- execption even after I did the fix provided.  Adding behaviorConfiguration="WcfService1.Service1Behavior" attribute to the service node fixed the problem.

Added By: Alexey (DevExpress Support) at: 8/16/2015 10:11:59 PM    Hello Jarkko,
The solution for this issue is already described in this example:
Troubleshooting 1. If WCF throws the "Entity is too large" error, you can apply a standard solution from StackOverFlow: http://stackoverflow.com/questions/10122957/

Viewing all 7205 articles
Browse latest View live


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