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

How to use a stored procedure as a report data source (System.Data.DataSet)

$
0
0

This approach is actual prior to version 14.1. Starting with version 14.1, use the approach illustrated in the How to bind a report to a stored procedure provided by the SQL Data Source in a WinForms application example.

The simplest method to use a stored procedure with parameters as a report data source is to create a corresponding TableAdapter in the VS DataSet designer.

To avoid the "Expected parameter was not supplied" error, when using parameterized stored procedure, please make certain whether the corresponding TableAdapter is detached from the XtraReport.DataAdapter property and the necessary parameter value is manually provided. You can use the Report Parameters for this purpose. Finally, fill the report's data source in the XtraReport.BeforePrint event handler by the TableAdapter.Fill() method call.


Associate an application with a particular file extension to open it by this application

How to vertically align the XRCheckBox in the XRTableCell based on the neighbor cell text

$
0
0

In this example, the Graphics.MeasureString Method is used to measure the actual height of the text contained in the XRTableCell. The XRCheckBox location is updated based on this height. All this logic is executed in the XRCheckBox.BeforePrint event handler. Note that in this scenario, correct conversion methods between Pixels and ReportUnits are required. The GraphicsUnitConverter class is used for this purpose.

How to use the CalculateDocumentVariable event to insert formatted content via DOCVARIABLE

$
0
0

This example illustrates how to use a Document.CalculateDocumentVariable Event to insert a formatted content via the DOCVARIABLE field with a parameter that is specified via the MERGEFIELD field. The formatted content is loaded into a non-visual RichEditDocumentServer component, which in turn is assigned to the e.Value parameter of a CalculateDocumentVariable event handler.

See also:
How to use document variable (DOCVARIABLE) fields
How to implement mail merge in a RichEditControl
How to: Perform a Mail Merge

Question Comments

Added By: Andrey Kushnarev at: 12/16/2015 9:03:23 AM    

How to get DocumentPosition of the current calculated DOCVARIABLE field?
I need to retrieve Font information from this position.

Added By: Oleg (DevExpress Support) at: 12/17/2015 12:18:36 AM    

Hello Andrey,
To process your recent post more efficiently, I created a separate ticket on your behalf: T325615: How to get a result range of a DOCVARIABLE field. This ticket is currently in our processing queue. Our team will address it as soon as we have any updates.

Added By: Petar Kosama at: 8/24/2016 8:01:46 AM    I have the problem that DOCVARIABLEs aren't being calculated when placed in the header of the document. If they are placed in the content then it works properly.

Please help, how do I get the docvariables in header updated?

Thanks Added By: Mariya (DevExpress Support) at: 8/24/2016 8:08:55 AM    

Hello,

I've created a separate ticket on your behalf (T418758: How to update DOCVARIABLE fields in the document header). It has been placed in our processing queue and will be answered shortly.

Isolate extension settings into separate helper / a partial view for multiple extensions

$
0
0
This example is more specific to ASP.NET MVC platform rather than to our extensions. It illustrates two popular techniques which can be used with any extensions (we chose a GridView extension for this example):

1) A separate helper class that holds extension settings. This technique might be useful in numerous scenarios. A couple of examples:

E3898 - How to export GridView data to different rich text formats
E3997 - Scheduler - Lesson 3 - How to Use Scheduler in complex views

In our example we define the most flexible form of extension method in the setting helper class:
[C#]
publicstaticGridViewSettingsCreateGridViewSettings(thisWebViewPageview,GridTypegridType)
[VB.NET]
<System.Runtime.CompilerServices.Extension> _PublicFunction CreateGridViewSettings(ByVal view As WebViewPage, ByVal gridType As GridType) As GridViewSettings
Note that we use the WebViewPage Class (System.Web.Mvc) class as the first parameter here. This allow us to access all the APIs which are available in the regular MVC views. For instance, you can use "view.Html", "view.Url", "view.ViewData", etc. members to access HtmlHelper, UrlHelper (both of them are illustrated in the source code of this example), ViewData and other APIs in convenient manner.

2) A single partial view (GridViewPartial.cshtml / GridViewPartial.vbhtml) is used to display multiple extensions. We pass the "gridType" parameter to the corresponding action method to determine which extension should actually be rendered:
[C#]
@Html.Action("GridViewPartial",new{gridType=GridType.Invoices})
[VB.NET]
@Html.Action("GridViewPartial", NewWith {.gridType = GridType.Invoices})
This parameter value comes up to the extension method in the setting helper class (we use the ViewData dictionary to pass it to the partial view) and here we use it to render specific content.

See Also:
Extension Methods (C# Programming Guide)
Question Comments

Added By: Włodzimierz Oleksiw at: 7/4/2016 9:53:46 AM    And if we have 1000 gridview with different columns ? Create 1000 extansion method for them?
Added By: Alessandro (DevExpress Support) at: 7/4/2016 10:16:59 AM    We will answer this question in the T399467: GridView - Add a hyperlink to template form code ticket. This ticket is currently in our processing queue. Our team will address it as soon as possible.Added By: Lucian Bumb 1 at: 7/5/2016 12:12:00 PM    There is any performance advantages of using this approach? (excluding the fact that the helpers can be used in export settings)? 

Added By: Alessandro (DevExpress Support) at: 7/5/2016 12:25:31 PM    

Hello,

I've created a separate ticket on your behalf (T400063: T191698: How to isolate extension settings into separate helper class and share a single partial view to display multiple extensions - Performance). It has been placed in our processing queue and will be answered shortly.

Open the leftmost tab with invalid editors (PageControl is placed in EditForm template)

$
0
0

This example is devoted to the scenario when there is a PageControl with Data Editors in the Edit Form template of the GridView extension and we need to validate the editors. In this scenario, it is necessary to use the approach illustrated in this example to activate the first tab with the invalid editors.

Show alert notifications of only appointments that are associated with the current user

$
0
0

This example illustrates how to filter reminder alerts shown in the Reminder Form. They are filtered according to the currently logged user.

To implement this scenario, you should handle the SchedulerStorageBase.ReminderAlert Event and the following property values to allow/ignore a particular alert notification:

ReminderBaseAlertNotification.Ignore Property
ReminderBaseAlertNotification.Handled Property

Use the e.AlertNotifications parameter of the ReminderAlert event to iterate through the currently arrived alert notifications.

See also:
Reminders for Appointments
How to handle the RemindersFormShowing event and invoke the reminder form manually

How to implement an editor for the XRRichText with drag&drop from the field list

$
0
0

The following example demonstrates how to implement a custom rich text control with the editor for the XRRichText.Rtf property. This editor supports drag and drop from the field list.


Toggle visibility of Ribbon categories that correspond to the specific doc element types

$
0
0

This example illustrates how to display/hide the following Ribbon categories depending of the selection location:

-Table Tools
-Header&Footer Tools
-Picture Tools

We handle the following events for this purpose:

RichEditControl.StartHeaderFooterEditing
RichEditControl.FinishHeaderFooterEditing
RichEditControl.SelectionChanged

Note that this approach is also illustrated in the "Ribbon UI" demo module, shipped along with the XtraRichEdit Suite (see Demos in Installation). The same approach can be implemented in WPF and SL platforms too (refer to the corresponding demo modules).

See Also:
How to: Create a Simple Word Processor with Ribbon Menu

Update an associated column editor when the ComboBox column editor value is modified

$
0
0
This as an MVC version of the T359598 - ASPxGridView - How to update an associated column editor in the Edit Form when the GridViewDataComboBoxColumn editor value is modified code example. A custom callback to the server is handled via the jQuery.ajax function (e.g., see E4063 - How to use the jQuery.ajax function with DevExpress MVC Extensions)

Note that we have used the techniques from the following webpages in this example:

Passing Values to a Controller Action through Callbacks
T191698 - How to isolate extension settings into separate helper class and share a single partial view to display multiple extensions

Actual updating of the underlying datasource is not implemented in this example. Please review the E3983 - GridView - How to edit in memory data source code example if you are interested in this scenario.

Creating a Master-Detail Report using subreports that are populated via stored procedures

$
0
0

This example demonstrates how to create a Master-Detail Report using subreports. Data for reports is retrieved from the server via stored procedures. A parameter for a stored procedure that retrieves master data is selected by end-users from the DropDownList control and passed to the master report via its Parameter object (see the Report Parameters) in the Page_Load event handler. Later, in the XtraReport.BeforePrint event handler, the value of this parameter is passed to the TableAdapter.Fill() method that invokes a stored procedure. A parameter for a stored procedure that retrieves detail data is obtained via the XtraReportBase.GetCurrentColumnValue Method and passed to the subreport via its own Parameter object in the XRSubreport.BeforePrint event handler of the XRSubreport control within the master report. Finally, in the XtraReport.BeforePrint event handler of the subreport, the value of this parameter is passed to the TableAdapter.Fill() method that invokes the second stored procedure.

The Northwind_StoredProcedures.sql file containing stored procedures is included (tested with MS SQL Server 2005). You should create them in the Northwind database prior to running this example.

Note 1:
Since parameterized TableAdapters are used in this example, and parameter values are provided manually, you should make sure that the TableAdapter is detached from the XtraReport.DataAdapter property for both reports. Otherwise, the "Expected parameter was not supplied" error might occur. BTW, we have a suggestion to provide an automatic parameter passing: Parameters - Automatically create corresponding parameters for table adapters and stored procedures. If you find this functionality useful, you can increase its popularity by tracking it.

Note 2:
A master report instance in this example is assigned to the ReportViewer.Report property manually. At that point, you should make sure that the ReportViewer.Report property value is not set at design time. Please review the Troubleshooting: The Report Toolbar isn't working, so it's impossible to navigate to other pages or export the report Knowledge Base article for more information on this subject.

Note 3:
The Master-Detail Report in this example is created via subreports only to demonstrate the parameters passing technique. Since the "Categories" and "Products" tables in the Northwind database have a relation by default, creating a Master-Detail Report via the DetailReportBand is preferable. Please review the Master-Detail Report help section for more information.

Related examples:

How to dynamically produce a web report using the SQL query with parameters as data source
How to pass a parameter to a web report
How to query a report's parameters in a Web application using a combo box control
How to use a stored procedure with parameters as a report data source in a Web application
How to use a stored procedure with parameters as a report data source in a WinForms application

How to customize the RichEditControl context menu based on the end-user input

$
0
0

This example illustrates how to customize the RichEditControl context menu based on the end-user input. The main idea of this functionality implementation is to handle the RichEditControl.ContentChanged Event and analyze characters displayed nearby the caret. The following Document Interface members are used for this purpose:

SubDocument.GetText Method
Document.CaretPosition Property

Then the RichEditControl.GetBoundsFromPosition Method is called to obtain a location where the context menu should be invoked. Take special note of the way a RichEditControl Class descendant is created with the ShowMenu method, which allows you to invoke the menu programmatically. When the menu is invoked, the RichEditControl.PopupMenuShowing Event is raised, which allows you to customize the menu items.

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 Lesson 2 - Provide Bars UI for a RichEditControl and Lesson 3 - Provide Ribbon UI for a RichEditControl ). If you wish to reuse RichEditControl UI for several RichEditControls on the page, execute the following steps:

1) Define a special RichEditControlProvider in xaml and change bindings of all toolbar items as follows:

RichEditControl="{Binding ElementName=richEditControl1}" -> RichEditControl="{Binding Path=RichEditControl, ElementName=richEditControlProvider1}"

This will point toolbar items to an intermediate component instead of a particular RichEditControl instance.

2) Remove binding to the BarManager component (it is defined for the RichEditControl.BarManager property):

BarManager="{Binding ElementName=barManager1, Mode=OneTime}"

3) Handle the RichEditControl.GotFocus event for all RichEditControls on the page to assign BarManager to the current RichEditControl and assign this RichEditControl to the RichEditBarController.RichEditControl property.

How to group data by predefined time intervals with the help of the PivotGridControl

$
0
0

This example demonstrates how to use a PivotGridControl to group data by predefined time intervals in order to represent it in the ChartControl.
Main aspects:
- The ChartControl.DataSource property is set to the PivotGridControl and a ChartControl.SeriesTemplate is used to bind the chart to data;
- The PivotGridField.GroupInterval property is used to group data by year and by month.

Implementing a hotkey for inserting a predefined value to the specific field editor

$
0
0
The main idea is to handle the client-side KeyDown, event, check key code (please note that the MouseEvent/KeyboardEvent object has properties like altKey, ctrlKey and  shiftKey). If a user has pressed a required key combination (Shift+T in this example), cancel the JavaScript event and set a required value (the current date in this example) for an editor using the client-side SetValue method.

To handle a column editor's KeyDown event, we use the GridViewEditDataColumn.PropertiesEdit.ClientSideEvents property. Please note that the PropertiesEdit value should be cast to a correct type of the Properties object before you can access the ClientSideEvents collection.

Enable a responsive layout to integrate GridView into a Bootstrap-enabled application

$
0
0
We use the Visual Studio Project Template to generate an application with responsive design. After that, we integrate the GridView extension into this application. Note that this extension provides responsive and adaptive layouts to accommodate to different devices' screens, but they are not enabled by default. Please review the following demos illustrating how to enable this functionality in a grid:

GridView - Responsive Layout
GridView - Adaptive Layout

Note:
Our Template Gallery also has the "Responsive Web Application" template.

See Also:
T250229 - How to make DevExpress web controls responsive

How to calculate IDs when inserting new appointments to ASPxScheduler bound to SQL Server

$
0
0

We will use the How to bind ASPxScheduler to MS SQL Server database example as a starting point. We see that the ID column in the CarScheduling table is defined as an Identity Column. By default the Identity Columns automatically assigns a value for each new row that has been inserted. But what if you want to insert your own value into the column for some reason (e.g. to reuse the IDs of deleted appointments)? To do this, update the SqlDataSource.InsertCommand as follows:

[ASPx]
<asp:SqlDataSourceID="SqlDataSourceAppointments"runat="server"InsertCommand="SET IDENTITY_INSERT CarScheduling ON; INSERT INTO [CarScheduling] (ID, ...) VALUES (@ID, ...); SET IDENTITY_INSERT CarScheduling OFF;"...
That is, use the SET IDENTITY_INSERT statement to disable/enable the automatic Identity Column insertion option. Note that in this scenario the ID parameter should be added to the SqlDataSource.InsertParameters collection.
In the code behind you can omit the SqlDataSource.Inserted event because you should implement your own logic to generate a unique ID. Please refer to the source code for more details.
See also:
</code>How to Insert Values into an Identity Column in SQL Server

A loading panel over the SchedulerControl for the WCF RIA Service data loading operation

$
0
0

This example illustrates how to display a loading panel over the SchedulerControl while appointment data is loaded via WCF RIA Services (see Lesson 1 - Bind a Scheduler to Data Using WCF RIA Services). Since the SchedulerControl does not include a built-in loading panel, you need to use a separate panel and display it manually. Note that we provide a standalone WaitIndicator panel that is defined in the DevExpress.Xpf.Core namespace. You can use it in the following manner:

[XAML]
<dxc:WaitIndicatorDeferedVisibility="{Binding Source={StaticResource ResourceKey=domainDataSourceAppointments}, Path=IsBusy}"/>

Here is a sample screenshot that illustrates this functionality in action:

Alternatively, you can create any custom panel. For instance, check the solution provided in the Show Loading Panel ticket.

Prior to running this example, it is required to register a CarsXtraScheduling database on your local SQL Server instance. You can download the corresponding SQL scripts from the How to bind ASPxScheduler to MS SQL Server database example.

GridView - Access/modify FilterExpression on the controller and save/load custom filters

$
0
0
This example illustrates how to pass the ASPxGridView.FilterExpression property value between the Controller, View and client-side parts of an application. In particular, we can store custom filters in a separate ListBox extension.

The main implementation details are:
- Pass the current FilterExpression value to the client side by handling the GridViewSettings.CustomJSProperties event (you can find a similar technique in the E5121 - GridView - How to implement data editing with hidden column code example).
- Pass the required FilterExpression value to the server side by calling the MVCxClientGridView.PerformCallback(Object) method. Alternatively, you can use the approach from the Passing Values to a Controller Action through Callbacks help section (e.g., see T146962 - GridView - How to track ClientLayout with a separate ListBox).
- Put the passed value to the ViewData dictionary to be able to intercept it in the View context and apply filter to GridView by handling the DataBound event.

DataLayoutControl - How to customize binding info and auto-generated layout items

$
0
0
This example shows how to handle the DataLayoutControl.FieldRetrieving and DataLayoutControl.FieldRetrieved events to customize binding information, and settings of auto-generated layout items and embedded editors.
Viewing all 7205 articles
Browse latest View live


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