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

How to color manually added shapes using the choropleth colorizer

$
0
0

This example demonstrates how to paint two triangles on a map using the choropleth colorizer.



ASPxDocumentViewer - How to customize a parameter editor (Creating a multi-select parameter)

$
0
0

This example demonstrates how to use a custom editor for the report's parameter to implement a multi-select parameter. The ASPxTokenBox control is used as a multi-select parameter editor.


The main idea of this approach is to use a report's parameter to pass a string that contains CategoryIDs separated by the '|' character to the report. Then on the report's DataSourceDemanded event handler the report's DataSource is populated based on the parameter value.
The ASPxDocumentViewer.CustomizeParameterEditors event handler is used to customize the report's parameter editor: Assign desired editor (ASPxEditBase class descendant) to the e.Editor property, and specify its Init event. Then use this Init event handler to initialize your custom parameter editor and bind it to the data.

See also:
DocumentViewer - How to customize a report parameter editor in MVC application

How to bind ASPxFormLayout to The XPODataSource

How to bind dxChart to AJAX-enabled WCF service in an ASP.NET application

How to use the dxChart in an ASP.NET WebForms application

How to customize the GridControl's print output

$
0
0

This example demonstrates how to override the default exporting process to take into account a custom drawn content provided via the GridView.CustomDrawFooterCell Event

Example Comments

Added By: Ilya Pogorelsky at: 8/16/2012 6:54:56 AM    

This only demonstrates drawing the grand total row. Can you please provide a sample that demonstrates a similar technique for drawing custom group footers?

Added By: Ilya Pogorelsky at: 8/16/2012 7:02:45 AM    

My Custom Footer Draw event looks like this:
        private void DrawFooter(FooterCellCustomDrawEventArgs e)
        {
                Rectangle rect1;
                Rectangle rect2;
                GridFooterCellInfoArgs args = e.Info;
                string originalText = e.Info.DisplayText;
                Rectangle originalBounds = args.Bounds;
                SplitBounds(originalBounds, 2, out rect1, out rect2);
                args.Bounds = rect1;
                e.Painter.DrawObject(args);
                args.Bounds = rect2;
                productTypeView.RaiseGetFooterCellDisplayText(e);
                e.Painter.DrawObject(args);
                args.Bounds = originalBounds;
                e.Info.DisplayText = originalText;

The problem with the attached sample, is that by the time "e" is passed into this method from the custom printing/eventing code, e.Painter is NULL. So I can't just say e.Painter.DrawObject(...). What should be done instead?

Added By: 'Matt' at: 10/4/2013 4:19:49 AM    

What is the code "Dim isPrinting As Boolean = e.Handled" good for? Is there code missing?
Regards Matt

How to generate and assign a sequential number for a business object within a database transaction, while being a part of a successful saving process (XAF)

$
0
0

This version of the How to generate and assign a sequential number for a business object within a database transaction, while being a part of a successful saving process example is primarily intended for XAF applications, because all the required operations to generate sequences are managed within the base persistent class. However, this code can be used in a regular non-XAF application based on XPO, as well.

For more convenience, this solution is organized as a reusable module - GenerateUserFriendlyId.Module, which you may want to copy into your project 'as is' and then add it as required via the Module or Application designers. This module consists of several key parts:

1. Sequence, SequenceGenerator, and SequenceGeneratorInitializer - auxiliary classes that take the main part in generating user-friendly identifiers.

Take special note that the last two classes need to be initialized in the ModuleUpdater and ModuleBase descendants of your real project.


2. UserFriendlyIdPersistentObject - a base persistent class that subscribes to XPO's Session events and delegates calls to the core classes above.


3. IUserFriendlyIdDomainComponent - a base domain component that should be implemented by all domain components that require the described functionality. Take special note that such derived components must still use the BasePersistentObject as a base class during the registration, e.g.:

[C#]
XafTypesInfo.Instance.RegisterEntity("Document",typeof(IDocument),typeof(BasePersistentObject));

4. Address, Contact, and IDocument are business objects that demonstrate the use of the described functionality for XPO and DC respectively.

IMPORTANT NOTES

1. If your connection string contains the Password parameter, then rework the SequenceGeneratorInitializer.Initialize method to not use the XafApplication.ConnectionString or XafApplication.Connection.ConnectionString properties, because XAF encrypts the specified password for safety reasons. Instead, either specify the connection string directly or read it from the configuration file.
2. The sequential number functionality shown in this example does not work with shared parts (a part of the Domain Components (DC) technology) in the current version, because it requires a custom base class, which is not allowed for shared parts.
3. This solution is not yet tested in the middle-tier and SecuredObjectSpaceProvider scenario and most likely, it will have to be modified to support its specifics.
4. As an alternative, you can use a more simple solution that is using the DistributedIdGeneratorHelper.Generate method as shown in the FeatureCenter demo ("%Public%\Documents\DXperience 13.X Demos\eXpressApp Framework\FeatureCenter\CS\FeatureCenter.Module\KeyProperty\GuidKeyPropertyObject.cs" ) or at How to generate a sequential and user-friendly identifier field within a business class

Example Comments

Added By: Mr. Murat YILMAZ at: 10/7/2012 9:15:18 AM    

Thanks for the example. I developed ISequentialNumber domain component which based on this article and code. Now this sequential number functonatility shon in this example work with domain components and shared parts.

using System;
using System.Collections.Generic;
using System.ComponentModel;

using DevExpress.ExpressApp.DC;
using DevExpress.Persistent.Base;
using DevExpress.Xpo;
using DevExpress.Xpo.Metadata;
using DevExpress.ExpressApp;
using DevExpress.Persistent.Base;
using DevExpress.Persistent.BaseImpl;
using DevExpress.Persistent.Validation;

using MyWay.Xaf.Module;
using MyWay.Xaf.Utils.Sequence;

namespace MyWay.Xaf.Module
{
    [DomainComponent]
    [NavigationItem]
    public interface ISequentialNumber
    {
        #region PROPERTIES

        #region SequentialNo

        [Persistent]
        string SequentialNo
        {
            get;
        }

        #endregion SequentialNo

        #region SequentialNumber
        
        [System.ComponentModel.Browsable(false)]
        [Indexed(Unique = false)]
        long SequentialNumber
        {
            get ;
            set;
        }

        #endregion SequentialNumber

        #endregion PROPERTIES
    }

    [DomainLogic(typeof(ISequentialNumber))]
    public class ISequentialNumberLogic
    {

            public static string Get_SequentialNo(ISequentialNumber instance)
            {
                return "asd" + instance.SequentialNumber.ToString();
            }

            

        private static object syncRoot = new object();
        private static SequenceGenerator sequenceGenerator;

        #region METHODS

        #region PUBLIC METHODS

        #region GenerateSequence

        public static void GenerateSequence(ISequentialNumber instance)
        {
            lock (syncRoot)
            {
                Dictionary<string, bool> typeToExistsMap = new Dictionary<string, bool>();

                foreach (object item in ((XPBaseObject)instance).Session.GetObjectsToSave())
                {
                    typeToExistsMap[((XPBaseObject)instance).Session.GetClassInfo(item).FullName] = true;
                }

                if (sequenceGenerator == null)
                {
                    sequenceGenerator = new SequenceGenerator(typeToExistsMap);
                }

                SubscribeToEvents(((XPBaseObject)instance).Session);
                OnSequenceGenerated(sequenceGenerator.GetNextSequence(((XPBaseObject)instance).ClassInfo), instance);
            }
        }

        #endregion GenerateSequence

        #endregion PUBLIC METHODS

        #region PROTECTED METHODS

        #region OnSaving

        public static void OnSaving(ISequentialNumber instance)
        {
            try
            {
                //base.OnSaving();
                if (((XPBaseObject)instance).Session.IsNewObject(instance) && !typeof(NestedUnitOfWork).IsInstanceOfType(((XPBaseObject)instance).Session))
                {
                    GenerateSequence(instance);
                }
            }
            catch
            {
                CancelSequence(((XPBaseObject)instance).Session);
                throw;
            }
        }

        #endregion OnSaving

        #endregion PROTECTED METHODS

        #region INTERNAL METHODS

        #endregion INTERNAL METHODS

        #region PRIVATE METHODS

        #region AcceptSequence

        private static void AcceptSequence(Session session)
        {
            lock (syncRoot)
            {
                if (sequenceGenerator != null)
                {
                    try
                    {
                        sequenceGenerator.Accept();
                    }
                    finally
                    {
                        CancelSequence(session);
                    }
                }
            }
        }

        #endregion AcceptSequence

        #region CancelSequence

        private static void CancelSequence(Session session)
        {
            lock (syncRoot)
            {
                UnSubscribeFromEvents(session);
                if (sequenceGenerator != null)
                {
                    sequenceGenerator.Close();
                    sequenceGenerator = null;
                }
            }
        }

        #endregion CancelSequence

        #region Session_AfterCommitTransaction

        private static void Session_AfterCommitTransaction(object sender, SessionManipulationEventArgs e)
        {
            
            AcceptSequence(e.Session);
        }

        #endregion Session_AfterCommitTransaction

        #region Session_AfterRollBack

        private static void Session_AfterRollBack(object sender, SessionManipulationEventArgs e)
        {
            CancelSequence(e.Session);
        }

        #endregion Session_AfterRollBack

        #region Session_FailedCommitTransaction

        private static void Session_FailedCommitTransaction(object sender, SessionOperationFailEventArgs e)
        {
            CancelSequence((Session)sender);
        }

        #endregion Session_FailedCommitTransaction

        #region SubscribeToEvents

        private static void SubscribeToEvents(Session session)
        {
            if (!(session is NestedUnitOfWork))
            {
                session.AfterCommitTransaction += Session_AfterCommitTransaction;
                session.AfterRollbackTransaction += Session_AfterRollBack;
                session.FailedCommitTransaction += Session_FailedCommitTransaction;
            }
        }

        #endregion SubscribeToEvents

        #region UnSubscribeFromEvents

        private static void UnSubscribeFromEvents(Session session)
        {
            if (!(session is NestedUnitOfWork))
            {
                session.AfterCommitTransaction -= Session_AfterCommitTransaction;
                session.AfterRollbackTransaction -= Session_AfterRollBack;
                session.FailedCommitTransaction -= Session_FailedCommitTransaction;
            }
        }

        #endregion UnSubscribeFromEvents

        #region OnSequenceGenerated

        private static void OnSequenceGenerated(long newId, ISequentialNumber instance)
        {
            instance.SequentialNumber = newId;
        }

        #endregion OnSequenceGenerated

        #endregion PRIVATE METHODS

        #endregion METHODS
    }
}

Added By: Luis Alberto Santiago at: 2/25/2013 8:06:36 PM    

Hi Mr. Murat YILMAZ, Can yo provide some example to use the class. I am looking it for shared parts

Added By: Andrew Bingham 2 at: 7/8/2013 3:38:51 AM    

I implemented this OK in a Solution

When I eimplmented it in a different solution I got an Exception
"Message: Value cannot be null.
Parameter name: Application"

thrown at:

    public static void Initialize() {
            Guard.ArgumentNotNull(Application, "Application");

Added By: Dennis (DevExpress Support) at: 7/11/2013 3:11:06 AM    

@Andrew: You forgot to add the following code:

public override void Setup(XafApplication application) {
            base.Setup(application);
            SequenceGeneratorInitializer.Register(application);
        }

You will not experience this and similar difficulties if you simply add the reusable module into your solution as per instructions above.

How to: Print a report without displaying a preview

$
0
0

This example demonstrates how to implement the InstantPrintReport Action that prints the current report without displaying its preview. The complete description is available in the How to: Print a Report Without Displaying a Preview (in Reports V2) topic.

Example Comments

Added By: Konstantin B (DevExpress) at: 3/6/2014 11:31:15 PM    

The How to: Print a Report Without Displaying a Preview (in Reports V2) topic will be published after the 13.2.8 version of XAF is released.


How to disable a particular row in the GridView

$
0
0

This example demonstrates how to create a helper class that allows you to enable/disable rows with ease. A disabled row is a row that has a specific appearance, and its in-place editors can't be activated.

Example Comments

Added By: Anthony Rich at: 7/8/2013 7:01:19 PM    

This seems like a bug in RowStateHelper.cs:
public GridView GridView
{
     set { UnSubscribeEvents(value); _GridView = value; SubscribeEvents(value); }
}

Shouldn't it be this:
public GridView GridView
{
     set { UnSubscribeEvents(_GridView); _GridView = value; SubscribeEvents(value); }
}
private void UnSubscribeEvents(GridView view)
{
     if (view != null)
     {
          view.RowCellStyle -= view_RowCellStyle;
          view.ShowingEditor -= view_ShowingEditor;
     }
}

Added By: Mary Xin at: 10/31/2013 8:52:47 AM    

I have a grid and it's showing a list of invoices from the table. If the invoice has been posted then I want the row disabled so a user can't edit it.

I am using vb.net. Can you tell me the steps how to do it? I am new to this grid control.

Thanks

Added By: Dean Martin at: 3/6/2014 12:51:27 PM    

This does not handle the situation where rows above a disabled row are deleted. Say I disable rows 5 thru 10. I can delete the rows above row 5 (rows 1 thru 4). And as I do that, what were rows 5 thu 10 now scroll up and I can now edit them or even delete them.

Added By: Dimitros (DevExpress Support) at: 3/6/2014 11:15:04 PM    

Yes, you are right, this example doesn't handle this situation. In this example, we just show the main idea how to accomplish this task. To simplify our code, we use a row datasource index to identify rows. If you want to add/delete rows and save their disabled state, I suggest that you use a key field value to identify rows. In this case, this approach will work correctly.

How to print DevExpress ASP.NET controls via XtraReports

$
0
0

This example illustrates how to print and/or export DevExpress ASP.NET controls by embedding them into an XtraReport.

In this example an ASPxGridView and WebChartControl are added to a report by using DevExpress.XtraReports.UI.PrintableComponentContainer objects.

Example Comments

Added By: Dhaval.Shah at: 11/21/2013 12:58:11 AM    

Hi all,
When I try to open this solution with VS2010 (DevEx 13.1.7), it says project is incompatible with current version of Visual Studio.
Can you please help?
Thanks

How to save an application's settings at runtime and then access them via a common interface from both Windows Forms and ASP.NET platform-dependent modules (Example)

How to show an error text for editors in the EditFormTemplateContainer.

$
0
0

This sample illustrates how to show an error text that is set for a column in the server-side RowValidating event handler within the error frame of the corresponding editor if the editor is placed in the EditFormTemplateContainer of ASPxGridView.

dxMap - How to display step by step directions

$
0
0

This example illustrates how to display step by step directions using Google Maps API. See the Directions Steps topic to learn more.

How to bind dxLookup to WebService

$
0
0

This example illustrates how to bind the dxLookup to a WebService using the DataSource object. Note that when you are using the DataSource with the dxLookup widget, it is also necessary to implement the byKey(keyValue) method.

Note: The current example does not implement the search mechanism. When using a web service, it is necessary to define the data searchString pattern to filter data at the web service level. For example:


[JScript]
if(loadOptions.refresh){return $.get('http://sampleservices.devexpress.com/api/Products', {... searchString: loadOptions.searchString || ''});}<bold>

See also:</bold>
dxLookup - Why the "Lookup callback was not defined" error is thrown when clicking an item if data is loaded from a web service

Example Comments

Added By: Domenik at: 7/26/2013 6:30:01 AM    

I used this way with some json data and it works as expected and the data gets listed BUT searching does not work... If i enter so letters nothing happens....

Added By: Marion (DevExpress Support) at: 7/26/2013 6:48:13 AM    

The current example does not implement the search mechanism. When using a web service, it is necessary to define the data searchString pattern to filter data at the web service level. For example:

if (loadOptions.refresh) {
       return $.get('http://sampleservices.devexpress.com/api/Products', {
            ...
            searchString: loadOptions.searchString || ''
        });
}

ASPxGridView - How to create a header's button that allows ungrouping a column on a click when AutoGenerateColumns="True"

$
0
0

This example demonstrates how to create a button inside the grid's header that allows ungrouping a column by a click.

We will use the HeaderCaption Template to add the UnGroup button to the column's header:


[C#]
classMyTemplate:ITemplate{publicvoidInstantiateIn(Controlcontainer){GridViewHeaderTemplateContainergridContainer=(GridViewHeaderTemplateContainer)container;stringfieldName=(gridContainer.ColumnasGridViewDataColumn).FieldName;Literalcaption=newLiteral();caption.ID="caption_"+gridContainer.ItemIndex.ToString();caption.Text=fieldName;container.Controls.Add(caption);ASPxImageimage=newASPxImage();image.ID="unGroup_"+gridContainer.ItemIndex.ToString();image.ImageUrl="~/Delete.png";image.ToolTip="UnGroup column";container.Controls.Add(image);image.ClientSideEvents.Click=string.Format("function(s, e){{ gridView.UnGroup ('{0}'); }}",fieldName);image.ClientSideEvents.Init="OnImageInit";}}

The OnImageInit function prevents the grid's sorting when a user clicks the UnGroup button:

[JScript]
function OnImageInit(s, e){var element = s.GetMainElement(); element.onmousedown = element.onmouseup = function(event){ event.cancelBubble = true;returnfalse;};}

However, it is necessary to set a template only for grouped columns. For this, use the following code:

[C#]
protectedvoidCreateUnGroupButton(){foreach(GridViewDataColumncolumninGridView1.DataColumns){if(column.GroupIndex!=-1){column.HeaderCaptionTemplate=newMyTemplate();}}}

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 display a chart within a range control using the numeric chart client

$
0
0

This example demonstrates how to set up a range control with the numeric chart client to display a chart with numeric data in the range control's background.

How to display a chart within a range control using the date-time chart client

$
0
0

This example demonstrates how to use the date-time chart client for a range control to display a chart with date-time data within the range control's viewport.

How to calculate a master property based on values from a details collection

$
0
0

See the How to: Calculate a Property Value Based on Values from a Detail Collection help topic for more information.

See Also:
XPO Best Practices
How to display details collections with descendant classes filtered by object type in a DetailView

Example Comments

Added By: Robert Fuchs at: 1/28/2013 9:01:23 AM    

Not using XAF web, just to let you know that there are warnings in 12.2.5:

Warning     1     Could not resolve this reference. Could not locate the assembly "DevExpress.Web.ASPxEditors.v12.2". Check to make sure the assembly exists on disk. If this reference is required by your code, you may get compilation errors.     WinWebSolution.Web
Warning     2     Could not resolve this reference. Could not locate the assembly "DevExpress.Web.ASPxGridView.v12.2". Check to make sure the assembly exists on disk. If this reference is required by your code, you may get compilation errors.     WinWebSolution.Web
Warning     3     The referenced component 'DevExpress.Web.ASPxEditors.v12.2' could not be found.      WinWebSolution.Web
Warning     4     The referenced component 'DevExpress.Web.ASPxGridView.v12.2' could not be found.      WinWebSolution.Web

How to apply conditional formatting to a range of cells

$
0
0

This example illustrates how to get started with conditional formatting that can be applied to cells that match a certain condition specified by a conditional formatting rule.
In particular, this sample demonstrates how to use the SpreadsheetControl API to create the following types of conditional formatting rules:
- a rule that formats cells whose values are above or below the average;
- a rule that highlights cells whose values are between or not between two specified values;
- a rule that formats top or bottom ranked values;
- a rule that highlights cells containing the given text;
- a rule that formats unique or duplicate values, blank cells and formula errors;
- a rule that highlights cells containing dates in the specified time period;
- a rule that formats cells whose values meet the condition expressed by the relational operator;
- a rule that uses a formula to determine which cells to format;
- a two-color scale conditional formatting rule;
- a three-color scale conditional formatting rule;
- a data bar conditional formatting rule;
- an icon set conditional formatting rule.



Viewing all 7205 articles
Browse latest View live