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

How to highlight the next or previous search result in the grid


How to prohibit addition of detached connectors to our WPF Diagram Control

$
0
0

This example demonstrates how to prevent creating detached connectors:

0

There are several scenarios when a user may create connector whose BeginItem/EndItem properties are empty:

1. Drawing a new connector using a tool. To cover this scenario, handle the AddingNewItem event and set e.Cancel to true if the BeginItem or EndItem properties are null:
[C#]
privatevoidDiagramDesignerControl_AddingNewItem(objectsender,DevExpress.Xpf.Diagram.DiagramAddingNewItemEventArgse){DiagramConnectorconnector=e.ItemasDiagramConnector;if(connector!=null){//...e.Cancel=connector.BeginItem==null||connector.EndItem==null;}}
2. Detaching a connector from an item. To prevent detaching connectors, set the BeginPointRestrictions and EndPointRestrictions properties to ConnectorPointRestrictions.KeepConnected.
3. Copying and pasting a connector. Handle the ItemsPasting event and set e.Cancel if pasted items contain detached connectors.
4. The use of the Move&Copy operation (pressing the Ctrl key and moving an item). Handle the BeforeItemsMoving event and set e.Cancel similarly to the previous point.

Server Mode - How to edit a focused GridView row in DataLayotControl

$
0
0

The standard approach (binding the GridControl and DataLayoutControl to the same collection) does not work in this scenario, because CurrencyManager does not manage Server Mode Data Sources. In addition, all Server Mode Data Sources except for XPServerCollectionSource are read-only.

This example demonstrates how to use the FocusedRowChanged event to synchronize the DataLayoutControl's data source (XPBindingSource or BindingSource) with a focused row.

Implementation details 1. Bind DataLayoutControl to a data source in the visual designer.
• If your ORM is XPO, add the XPBindingSource component from the toolbox. 1. Rebuild the project.
2. Select the XPBindingSource.ObjectClassInfo property in the Properties window, open the drop-down list, and choose an appropriate XPO class.
3. Assign XPBindingSource to the DataLayoutControl.DataSource property.

• If your ORM is EF or a different library, add the BindingSource component from the toolbox. 1. Rebuild the project.
2. Click the Project>Add New Data Source menu item.
3. Choose the Object Data Source Type and click Next.
4. Choose an appropriate class in the list and click Finish.
5. Assign BindingSource to the DataLayoutControl.DataSource property.

2. Retrieve fields.
3. Select GridView and subscribe to the FocusedRowChanged event.
4. Use the FocusedRowChangedEventArgs.Row property value to retrieve a focused object and add it to the data source.
A code example for XPBindingSource
[C#]
privatevoidGridView_FocusedRowObjectChanged(objectsender,FocusedRowObjectChangedEventArgse){XPBindingSource.DataSource=Session.GetLoadedObjectByKey<ServerSideGridTest>(e.Row);}
[VB.NET]
PrivateSub GridView_FocusedRowObjectChanged(ByVal sender AsObject, ByVal e As FocusedRowObjectChangedEventArgs) XPBindingSource.DataSource = Session.GetLoadedObjectByKey(Of ServerSideGridTest)(e.Row)EndSub
A code example for BindingSource
[C#]
privatevoidGridView_FocusedRowObjectChanged(objectsender,FocusedRowObjectChangedEventArgse){objectobj=DbContext.ServerSideGridTests.Single(e.Row);BindingSource.Clear();BindingSource.Add(obj);}
[VB.NET]
PrivateSub GridView_FocusedRowObjectChanged(ByVal sender AsObject, ByVal e As FocusedRowObjectChangedEventArgs)Dim obj AsObject = DbContext.ServerSideGridTests.Single(e.Row) BindingSource.Clear() BindingSource.Add(obj)EndSub

Files to look at:

MainForm.cs (VB: MainForm.vb)

(Obsolete) How to synchronize XtraGrid with CurrencyMangaer in Server Mode

How to serialize parameters of custom types

$
0
0

This example demonstrates how to support report parameters of custom types for an End-User Report Designer for WinForms.

Do the following to enable this feature:
1. Create a custom report design extension inherited from the ReportDesignExtension class.
2. Override the ReportDesignExtension.AddParameterTypes method to register custom parameter types.
3. Register a custom extension using the ReportDesignExtension.RegisterExtension method.
Assign the required report to the created extension by calling the ReportDesignExtension.AssociateReportWithExtension method.

How to display a report that uses a private (embedded) font in a DocumentPreviewControl

$
0
0

Unlike WinForms, where an embedded font can be registered globally using the PrivateFontCollection, WPF requires explicit reference to the embedded font. This sample application demonstrates how to work around this limitation.

See also:
E5198: How to use a private font (a custom font distributed with the application) in XtraReport

Note: This example targets the older version of our WPF report viewer called DocumentPreview. The new DocumentPreviewControl (v15.1+) does not use XAML for rendering document pages and therefore does not require any special handling with the exception of what's described in this MSDN article: How to: Create a Private Font Collection

Files to look at:

MainWindow.xaml
MainWindow.xaml.cs

DataGrid - How to conditionally disable selection checkboxes

$
0
0

This example describes how to conditinally disable row selection and selection checkboxes.

We recommend handling the selectionChanged event to prevent selecting disabled checkboxes. However, the Select All checkbox will work incorrectly after that. The cause of that issue is that dxDataGrid doesn't support this scenario out-of-the-box. A workaround for this scenario is shown in this GitHub repository. In this example, a row is disabled if its Approved value is false. The limitation of this workaround is that the remoteOperations option should be false.

How to: Use a Custom Value Source for a Colorizer


How to Track Changes to the Collection of Chart Selected Items

$
0
0

Use the WebChartControl.SelectedItemsChanged event to track changes in the collection of chart selected items.

In this example, the bar chart displays only points that correspond to the selected segments in the pie chart.

Custom GridControl - How to implement your own logic for filtering data in an auto filter row

$
0
0

This example illustrates how to create a custom grid to customize the mechanism of filtering data via the auto filter row. For this, the GridView.CreateAutoFilterCriterion methodis overridden.

This example demonstrates how to filter DateTime values in columns via the auto filter row by using the additional "<", ">", ">=" and "<=" filter operands.

Files to look at:

• [Custom Grid.cs](https://github.com/DevExpress-Examples/custom-gridcontrol-how-to-implement-your-own-logic-for-filtering-data-in-an-auto-filter-row-e3148/blob/13.1.4%2B/CS/WindowsApplication3/Custom Grid.cs) (VB: [Custom Grid.vb](Custom Grid.cs](Custom Grid.cs](https://github.com/DevExpress-Examples/custom-gridcontrol-how-to-implement-your-own-logic-for-filtering-data-in-an-auto-filter-row-e3148/blob/13.1.4%2B/CS/WindowsApplication3/Custom Grid.cs) (VB: [Custom Grid.vb](Custom Grid.cs)
Main.cs (VB: Main.vb)
Program.cs (VB: Program.vb)

Custom Drawing Engine Usage Example

Blazor DataGrid - How to use icons instead of default command buttons

$
0
0

This example illustrates how to create custom HTML elements in DxDataGrid's command columns, specify icons for them and use the StartRowEdit method to initiate editing an existing row or adding a new row.

DataGrid for Blazor - How to bind it to the Web API Service

$
0
0

There are two projects:

1. MyTestWebService
2. DataGridWithWebApiService
MyTestWebService

A sample project implementing a web API with ASP.NET Core.

ORM is EntityFrameworkCore.

The data base is "Northwind", and its backup is in this folder.

Restore the backup on your SQL server and change the connection string in this file correspondingly (see the OnConfiguring method).

DataGridWithWebApiService

This project uses the connection to the MyTestWebService web service. Deploy the MyTestWebService project, start it, and specify its address in this file

DataGrid for Blazor - How to use DxUpload inside a DxDataGrid's edit form to edit a field

$
0
0

This example illustrates how to upload a new image using the DxUpload component, save it to the server's folder and save the path to the corresponding image in the edited grid's row.

How to add a link to URI


How to use the PDF printer settings

$
0
0

This example shows how to print a document with custom printer settings.

The Universal Subscription or an additional Office File API Subscription is required to use this example in production code. Please refer to the DevExpress Subscription page for pricing information.

Files to look at:

Program.cs (VB: Program.vb)

RichEdit for Angular - How to customize the built-in ribbon

$
0
0

This example is a ready-to-use client Angular application with the DevExpress RichEdit component. It demonstrates how to modify the built-in ribbon in the RichEdit control.
The ribbon option allows you to access RichEdit's built-in ribbon. You can get required tabs and items using the getTab and getItem methods respectively.
Then, you can add or remove items using the insertItem and removeItem methods.

Documentation: Add RichEdit to an Angular Application

Requirements • To use the RichEdit control in an Angular application, you need to have a Universal, DXperience, or ASP.NET subscription.
• Versions of the devexpress npm packages should be identical (their major and minor versions should be the same).
Quick Start 1. Open the JS folder. In the command prompt, download and install npm packages that are used in the application:
npm install
2. In the same folder, run the following command to compile and run the application:
ng serve --open
See Also

Documentation:

Add RichEdit to an Angular Application
Rich Text Editor

Examples:

RichEdit Angular Application

How to generate database updater code for security roles created via the application UI in a development environment

$
0
0
Scenario

XAF developers often create initial security roles via the administrative UI (at runtime) in non-production databases of their test environments. The visual approach is often faster than writing C# or VB.NET code manually, especially for complex permissions with criteria (check screenshots). If you create initial roles at runtime with test databases, you need to eventually transfer this data to production databases on customer sites.

Solution

ModuleUpdater API and DBUpdater are standard means to seed initial data in databases with XAF.
We will demonstrate how to automatically create ModuleUpdater C# or VB.NET code for required roles created by XAF developers at runtime with test databases. XAF developers can easily copy and paste this ready code into their ModuleUpdater descendant and use the standard DBUpdater tool to seed data in production databases. We intentionally skip user creation code, because user names are often unknown at early stages and it is much easier to create and link users to predefined roles later in production environment.
image


Implementation Steps

Step 1. In the Solution Explorer, include RoleGenerator.csproj or RoleGenerator.vbproj into your XAF solution and then reference this RoleGenerator project from the YourSolutionName.Module one.

Step 2. Include the following files into your XAF solution projects

YourSolutionName.Module: RoleGeneratorController.cs or RoleGeneratorController.vb;
YourSolutionName.Module.Win: RoleGeneratorControllerWin.cs or RoleGeneratorControllerWin.vb;
YourSolutionName.Module.Web: RoleGeneratorControllerWeb.cs or RoleGeneratorControllerWeb.vb.

Step 3. Modify the YourSolutionName.Win/App.config and YourSolutionName.Web/Web.config files to add the EnableRoleGeneratorAction key under the appSettings section.

[XML]
<appSettings> ...<addkey="EnableRoleGeneratorAction"value="True"/></appSettings>

Step 4. Run the YourSolutionName.Win or YourSolutionName.Web project, select roles in the Role ListView, and click the Generate Role Action (in the WinForms project, this Action is under the Tools menu).

WinForms:

image

ASP.NET WebForms:

image

Step 5. Save the generated file and research its content. It contains code that creates initial roles based on data stored in your test database. To use this file in your XAF solution, consider one of these two strategies:

• Modify the existing YourSolutionName.Module/DatabaseUpdate/Updater.xx file based on the CreateUsersRole method code copied from the generated Updater.xx file.
• Include the generated Updater.xx file into the YourSolutionName.Module/DatabaseUpdate folder and modify the YourSolutionName/Module.cs or YourSolutionName/Module.vb file to use this new RoleUpdater class as follows:
// C#
using System;
using DevExpress.ExpressApp;
using System.Collections.Generic;
using DevExpress.ExpressApp.Updating;
namespace YourSolutionName.Module {
  public sealed partial class YourSolutionNameModule : ModuleBase {
    public override IEnumerable<ModuleUpdater> GetModuleUpdaters(IObjectSpace objectSpace, Version versionFromDB) {
      ModuleUpdater updater = new DatabaseUpdate.Updater(objectSpace, versionFromDB);
        ModuleUpdater roleUpdater = new RoleUpdater(objectSpace, versionFromDB);
        return new ModuleUpdater[] { updater, roleUpdater };
//...
[VB.NET]
' VB.NETImports SystemImports DevExpress.ExpressAppImports System.Collections.GenericImports DevExpress.ExpressApp.UpdatingNamespace YourSolutionName.Module {PublicNotInheritablePartialClass YourSolutionNameModuleInherits ModuleBasePublicOverridesFunction GetModuleUpdaters(ByVal objectSpace As IObjectSpace, ByVal versionFromDB As Version) As IEnumerable(Of ModuleUpdater)Dim updater As ModuleUpdater = New DatabaseUpdate.Updater(objectSpace, versionFromDB)Dim roleUpdater As ModuleUpdater = New DatabaseUpdate.RoleUpdater(objectSpace, versionFromDB)ReturnNew ModuleUpdater() {updater, roleUpdater}EndFunction'...
Customization for Custom Security Roles

If you have a custom security role class (for instance, ExtendedSecurityRole as in these examples: one, two) and this class has custom properties, you need to include these properties into the generated code. To do this, handle the RoleGenerator.CustomizeCodeLines event in the RoleGeneratorController class added at Step 2:

// C#
using System.Collections.Generic;
using System.Linq;
using DevExpress.ExpressApp;
using DevExpress.ExpressApp.Actions;
using DevExpress.Persistent.Base;
using RoleGeneratorSpace;
namespace XafSolution.Module.Controllers {
    public abstract class RoleGeneratorController : ViewController<ListView> {
    //...
        protected void RoleGeneratorAction_Execute(object sender, SimpleActionExecuteEventArgs e) {
            RoleGenerator roleGenerator = new RoleGenerator(roleType);
            roleGenerator.CustomizeCodeLines += RoleGenerator_CustomizeCodeLines;
            IEnumerable<IPermissionPolicyRole> roleList = e.SelectedObjects.OfType<IPermissionPolicyRole>();
            string updaterCode = roleGenerator.GetUpdaterCode(roleList);
            SaveFile(updaterCode);
        }
        private void RoleGenerator_CustomizeCodeLines(object sender, CustomizeCodeLinesEventArg e) {
            ExtendedSecurityRole exRole = e.Role as ExtendedSecurityRole;
            if(exRole != null) {
                e.CustomCodeLines.Add(string.Format("role.CanExport = {0};", exRole.CanExport.ToString().ToLowerInvariant()));
            }
        }
    }
}
[VB.NET]
' VB.NETImports SystemImports System.Collections.GenericImports System.ComponentModelImports System.LinqImports DevExpress.ExpressAppImports DevExpress.ExpressApp.ActionsImports DevExpress.ExpressApp.SecurityImports DevExpress.Persistent.BaseImports RoleGeneratorSpaceImports XafSolution.SecurityNamespace XafSolution.Module.ControllersPublicMustInheritClass RoleGeneratorControllerInherits ViewController(Of ListView)'...ProtectedSub RoleGeneratorAction_Execute(ByVal sender AsObject, ByVal e As SimpleActionExecuteEventArgs) Handles roleGeneratorAction.ExecuteDim roleGenerator AsNew RoleGenerator(roleType)AddHandler roleGenerator.CustomizeCodeLines, AddressOf RoleGenerator_CustomizeCodeLinesDim roleList As IEnumerable(Of IPermissionPolicyRole) = e.SelectedObjects.OfType(Of IPermissionPolicyRole)()Dim updaterCode AsString = roleGenerator.GetUpdaterCode(roleList) SaveFile(updaterCode)EndSubPrivateSub RoleGenerator_CustomizeCodeLines(ByVal sender AsObject, ByVal e As CustomizeCodeLinesEventArg)Dim exRole As ExtendedSecurityRoleTS = TryCast(e.Role, ExtendedSecurityRoleTS)If exRole IsNot NothingThen e.CustomCodeLines.Add(String.Format("role.CanExport = {0}", exRole.CanExport))EndIfEndSubEndClassEndNamespace'...

How to generate SQL script for schema migration

$
0
0

This example illustrates how to programmatically generate the SQL-script for database schema migration with eXpress Persistent Objects.

Files to look at:

Program.cs (VB: Program.vb)

GridView for MVC - How to use the Tokenbox control to filter a TokenBox column in a Filter Row

Viewing all 7205 articles
Browse latest View live


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