You can use the "C:\Users\Public\Documents\DXperience 12.1 Demos\Data\nwind.mdb" database in this solution.
LayoutView - How to customize CustomizationForm
dxChart - How to convert a chart SVG presentation to an image using canvas
This example illustrates how to obtain SVG presentation from a chart and convert it to an image using the canvas element.
How to create a master-detail report bound to an ORM (Entity Framework) model in MVC applications
This example demonstrates how to create a master-detail report bound to Object Relational Model in ASP.NET MVC applications.
This example uses the Entity Framework ORM model to provide a report with data, but you can use any object model instead.
Bind your XtraReport to your model master class by using the approach suggested in the Providing Data to a Web Report => Design-Time Data Binding Using BindingSource help topic. After your report is bound to the master class you can easily insert a detail report band by using the context menu in the report designer, as shown below:
FAQ:
- Why does the "Data binding directly to a store query (DbSet, DbQuery, DbSqlQuery) is not supported. Instead populate a DbSet with data, for example by calling Load on the DbSet, and then bind to local data." exception occur?
This example uses Entity Framework 4 so you can easily bind the report to the query result. However note that starting with Entity Framework 4.1 you can not bind components to queries, so you need to convert your query to the List and then bind your report to this List. Use the following code for this purpose:
[C#]report.DataSource=(fromcategoryinDataContext.Categoriesselectcategory).ToList();
[VB.NET]report.DataSource = _ (From category In DataContext.Categories _Select category).ToList()
See also:
How to bind a report displayed in the DocumentViewer extension to the model's data
How to replace Excel XLL Add-in UDF with a custom function
This example defines a custom worksheet function named Discountand adds it to the collection of worksheet functions in the SpreadsheetControl. The SpreadsheetControl loads a document with formulas which reference the Discount function defined in the external Excel XLL Add-in. After loading the document, function names in formulas are corrected to remove the "_xll.DiscountXLL.MyFunctions." name prefix, leaving only the function name Discount. Finally the worksheet formulas are calculated using the custom Discount function defined in this example.
ASPxDocumentViewer - How to customize a parameter editor (Creating a multi-select parameter)
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 colorize map contours loaded from Shapefiles using the Choropleth colorizer
This example demonstrates how to paint each map contour in a specific color depending on GDP data from Shapefiles (Countries.dbf, Countries.shp).
ClickOnce deployment of an application with Developer Express .NET Windows Forms components
This is a sample project for the article AK3799. It demonstrates how to use the ClickOnce deployment for publishing your applications with our components. To accomplish this task you should to change the Publish Status option of the DevExpress.~ assemblies from Prerequisite (Auto) to Include.
See Also:
A tool for collecting the required DevExpress assemblies for further application deployment
A240
A928
ClickOnce Deployment and Localization
Introducing Client Application Deployment with "ClickOnce"
How to disable a particular row in the GridView
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;
}
}
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 PMThis 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 PMYes, 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 load a file on the callback of the ASPxGridView using the ASPxWebControl.RedirectOnCallback method
By default, it is impossible to load files on callbacks:
The Concept of Callbacks
However, there's a solution that allows you to overcome this problem. Our ASPxWebControl class has the RedirectOnCallback method that allows redirect to another page during a callback.
In our situation, we can create a specific "download" page and call a method which loads a file in the Page_Load event handler of this page.
This sample shows how to load a file in the click of a custom button of the ASPxGridView.
See also:
ASPxTreeList - How to download a file by clicking a custom command button
ASPxGridViewExporter - How to show content document in a new tab
How to refresh the Field List in the End-User Designer
This example demonstrates how to programmatically update the Field List in the End-User Designer. This may be required when a data source is created and bound to a report at runtime, and isn't present in the designer host of the End-User Designer. For instance, this situation occurs when a data source is represented by a list (e.g. ArrayList), as demonstrated in the sample below.
To accomplish this task, we've introduced the FieldListDockPanel.UpdateDataSource method, which should be called after assigning a data source to a report.
Example Comments
Added By: BGood2 at: 3/27/2014 3:59:31 PM
Tried this sample with v13.2.8 in Visual Studio 2012 on Windows 7 32 bit VM. Menu item "Bind to a DataSource" is disabled after the app starts.
If I bypass the code in Form1_Load and don't call xrDesignPanel1.ExecCommand(ReportCommand.NewReport);, the menu item is enabled, but the code in BindReportToData() fails because xrDesignPanel1.Report is null.
Suggestions?
How to create a data source wrapper that adds an empty item to the lookup list
This example demonstrates how to display an empty (blank) item in the dropdown list of the LookUpEdt control. This approach is also applicable to GridLookUpEdit / RepositoryItemGridLookUpEdit.
See Also:
How to clear the currently selected value in the LookUp editor
How to: Use DevExpress Fluent API with DevExpress controls
This example demonstrates how you can use DataAnnotation attributes with DevExpress controls (GridControl, DataLayoutControl, PropertyGridControl).
How to handle the Back button click
This example demonstrates how to handle the Back button click. The HtmlApplication.navigatingBack event allows us to accomplish this task. However, this event handler does not provide information about the current view and its view model. Sometimes it is necessary to perform some actions before navigating. To solve this problem, we declare an additional option in the context of our application - HtmlApplication.currentViewModel. This option will store the necessary information about the current view, namely the current view model. The HtmlApplication.viewShown event handler allows you to get a view model of the shown view. We can get this view model and set it to our new option. In this case, we can access the current view model using HtmlApplication.currentViewModel and perform necessary actions in the HtmlApplication.navigatingBack event handler. Moreover, we can cancel back navigation in this event handler using the cancel option of the event handler argument as shown below:
[JScript]Application1.app.currentViewModel = null; Application1.app.viewShown.add(function(e){ Application1.app.currentViewModel = e.viewInfo.model;}); Application1.app.navigatingBack.add(function(e){if(Application1.app.currentViewModel.name == 'View1'){if(!confirm("Are you sure you want to leave View1 ?")){ e.cancel = true;return;}//Execute the required code} Application1.app.currentViewModel = null;});
This code demonstrates how to perform actions when a user clicks the Back button on View1.
How to populate a List View with data from a LINQ query
Scenario
Sometimes it is important to show a readonly ListView with custom data obtained from the database, rather than through standard XPO mechanisms, by means of loading entire persistent objects.
While this custom data may include certain properties of your XPO classes, in a general case, it may come from anywhere, including but not limited to, a raw SQL query, stored procedure, database view or a very complex LINQ query returning only a subset of persistent class properties or even custom data fields. While the first scenarios can be solved by mapping a persistent class to a database view, the second group of scenarios is optimal in implementing a custom form/control (check How to show custom forms and controls in XAF (Example) for more details) or a custom CollectionSource.
Here, we will demonstrate how the latter option can be realized to display data from a custom LINQ query using the LINQ to XPO approach.
In particular, we want to show a list of employees with maximum orders:
Steps to implement
1. Include the XAF.LinqToXpo module project in your solution and make sure it builds successfully.
This module is supposed to generate custom ListView nodes in the Application Model with the _Linq suffix so that this ListView uses data returned by a predefined method (see the XPQueryMethod attribute for the ListView node) using LINQ.
To provide this custom ListView with data, a custom CollectionSourceBase class descendant is implemented (see the XAF.LinqToXpo\LinqCollectionSource.xx file). It is enabled for a custom ListView via the XafApplication.CreateCustomCollectionSource event (see the XAF.LinqToXpo\Module.xx file).
2. Invoke the Module Designer for YourSolutionName.Module project and drag and drop the XafLinqToXpoModule component to the Required Modules list (this component should automatically appear in the Visual Studio Toolbox after executing the previous step).
3. Implement the public static methods that accept DevExpress.Xpo.Session as a parameter and return System.Linq.IQueryable as a result in your persistent classes, where required.
Consider the following signature for more clarity: public static System.Linq.IQueryable MethodName(DevExpress.Xpo.Session session);
Within the method body, use the LINQ to XPO approach to return a required data set based on XPQuery<T>. If you want to return a custom property as part of your data set which does not exist within your XPO data model, then include it into the selected part of the query with a custom name (e.g., Employee_Linq, Orders_Sum_Linq, etc.).
Mark these methods with the XAF.LinqToXpo.QueryProjectionsAttribute to specify that comma-separated names of data properties will be included as a query result.
Refer to the NorthwindDemo.Module\PersistentObjects.xx for an example.
4. Invoke the Model Editor for YourSolutionName.Module project and add custom calculated fields with dummy expressions for each specified custom property which is not part of your default XPO data model. Refer to the NorthwindDemo.Module\Model.DesignedDiffs.xafml file for an example.
IMPORTANT NOTES
1. This example uses the Northwind database for testing. You can download the database creation scripts for testing from here.
2. Since a Linq-based ListView may contain custom data sets and not entire persistent objects in a general case, certain standard Controllers are disabled here (e.g., you cannot open a detail form for this data record or create a new object). Refer to the XAF.LinqToXpo\DisableStandardActionsLinqListViewController.xx file for more details.
3. If you want your default ListView to include custom calculated values, then it is possible to use the built-in Custom Fields feature for that purpose.
How to export selected map items to an image
The following example demonstrates how to export selected map items to an image.
To do this, handle the MapControl.ExportMapItem event and set the ExportMapItemEventArgs.Cancel property to true if the map item is not selected (the ExportMapItemEventArgs.IsSelected property is set to false).
Then, call the MapControl.ExportToImage method using the map path (where the map image should be stored) and the specified image format ( e.g., .png).
How to show image tiles loading progress from the web data service
This example shows how to visualize the progress of loading image tiles from the OpenStreetMap data provider using a progress bar.
To accomplish this task, handle the ImageTilesLayer.RequestDataLoading event and specify how the progress bar should be updated using the UpdateProgressBar method. Then, handle the LayerBase.DataLoaded event to specify the final state of the progress bar when the data load is finished.
WinForms SpreadsheetControl API - Part 2
This example is the second part of the SpreadsheetControl API set of examples that demonstrates how to use the SpreadsheetControl API to programmatically manage spreadsheet documents, without the need for Microsoft Excel to be installed.
This sample introduces API properties and methods used to perform the following operations:
- Insert, delete and modify pictures
- Add a hyperlink to a picture
- Add custom functions to the spreadsheet
Starting from v2013 vol.2:
- Create a table
- Apply a custom style to the table
How to generate a document layout in code via the Snap application programming interface (API)
This example illustrates the Snap API that is used to generate a document from scratch and connect it to data completely in code.
The following code generates a tabular report layout. For a sample code that creates a mail-merge report (in the context of SnapDocumentServer), refer to the following example: How to automatically create mail-merge documents using the Snap Document Server.
SnapControl extends the RichEditControl's API and introduces the SnapList class that is used to insert dynamic data elements into a document.
To generate a data-aware Snap document, do the following:
- Create a Snap application and connect it to a data source.
- Add a SnapList to the SnapDocument.
- To generate the SnapList layout, define the ListHeader, ListFooter, and RowTemplate.
- Inject data fields into the document (e.g., by using SnapText to display text data).
- Format the document content (see the FormatList method implementation in the Form1.cs file of the sample solution).
- If required, apply grouping, sorting, and/or filtering to the SnapList content.
A SnapEntity is open to customization only after calling its BeginUpdate method and not after the EndUpdate method is called to apply the new settings (see the GenerateLayout method in the Form1.cs file of the sample solution).
How to provide data to a grid via WCF Web Services in server mode
The following example demonstrates how to use WCF (Windows Communication Foundation) to provide data for the DXGrid control. Note that in this case the DXGrid control works in server mode. This guarantees the best possible performance with large datasources for passing data from a server to a client-side DXGrid control. Important Note: For version 11 and lower, this example makes use of the open source InterLINQ library. Therefore, if you want to use it in your applications, you should review its license. For a detailed description of this approach, refer to the following Knowledge Base article: K18300
Example Comments
Added By: annalisa giacoponi at: 11/25/2013 6:54:21 AM
How can I pass one or more parameters at the CreateHandler method to filter query result?
thanks
Hi Annalisa,
I've created a separate ticket on your behalf: http://www.devexpress.com/Support/Center/Question/Details/Q463300. We will answer you there.
Thanks
How to draw a rectangle around selected cells and implement a copy/paste functionality
Unlike the Excel sheet, the XtraGrid doesn't provide a copy/paste functionality, because it displays data of different types and therefore. So, this functionality can't be used in common situations. This example demonstrates how to implement a copy/paste functionality manually, assuming that all data is of the String type. Also, this example demonstrates how to draw a blinking rectangle around the selected area using the GridView.CustomDrawCell event. The CellSelectionHelper component, created within this example, can be simply placed on the form in the VS designer. All you need to make it work is to assign an appropriate GridView to it.