Quantcast
Viewing all 7205 articles
Browse latest View live

OBSOLETE - How to: Customize a Window Caption and Status Messages


How to use Criteria Property Editors

This example illustrates the specifics of using Criteria Property Editors in an XAF application. The complete description is available in the How to: Use Criteria Property Editors help topic.

Note: In this example, the SessionMixingException may occur if you refresh a list view filtered by criteria with object references. Several workarounds for this issue are provided in the E932 - object belongs to a different session after refresh filter with Business Entity ticket. The issue will be eliminated once the CollectionSourceBase - Refresh objects referenced by the applied criteria when the Object Space is reloaded suggestion is implemented.

See Also:
How to dynamic change the ObjectType Criteria Property Editors

Question Comments

Added By: Marco Castro at: 6/25/2014 5:24:38 AM    

Hello,

The idea is great but the most usefull fielter don't work. This filter, as example, can be created but when executed don't work because a popup window that should appear so the user can fill the desired name is not poped up.

Contains([FirstName], ?)

Thanks,
Marco Castro

Added By: Konstantin B (DevExpress) at: 6/26/2014 1:56:16 AM    Hi Marco,

I am afraid there is no option to display a popup dialog from the SingleChoiceAction's Execute event handler. This scenario will probably be supported once the following suggestion is implemented Actions - Provide the capability to easily manage placement of Actions (file menu, toolbar, grid or context (popup) menu) without customizing the template.

Added By: Douglas Zuniga at: 7/5/2017 9:06:57 AM    Hi Guys!
How can I add more custom functions for Date properties using xaf? Added By: Michael (DevExpress Support) at: 7/6/2017 12:41:33 AM    

Hello Douglas,

I've found that you already submitted a ticket with this question - T532838 - How to add more custom functions to PopupCriteriaPropertyEditor. We will answer you there.

Added By: Sławomir (debesciak) Łopuszański at: 2/6/2018 6:51:00 AM    is any easy way to add option to add new filter criteria from grid filter settings ?
In example user enter own filter or criteria on listView and if want save this filter for later use press a button "Store criteria" and this is added to FilteringCriterion table ? Added By: Michael (DevExpress Support) at: 2/6/2018 7:34:32 AM    

@Sławomir: I've created a separate ticket on your behalf (T603628: Based on E932, how to save the current grid filter as a new FilteringCriterion object). It has been placed in our processing queue and will be answered shortly.

How to customize the underlying database provider options and data access behavior in XAF

IMPORTANT NOTE

This article describes some advanced customization techniques and low-level entities of the framework with regard to data access, which may be required in complex scenarios only.
So, if you just want to change the connection string, e.g. to use the Oracle instead of the Microsoft SQL Server database, then you would better refer to the Connect an XAF Application to a Database Provider article and documentation on your database provider instead. The XAF integration of supported ORM libraries is also described in the Business Model Design section of the framework's documentation.


Introducing IObjectSpaceProvider and IObjectSpace
XAF accesses data from a data store through special abstractions called - IObjectSpaceProvider and IObjectSpace.
The IObjectSpace is an abstraction above the ORM-specific database context (e.g., the DBContext used in Entity Framework or the Session in XPO) allowing you to query or modify data.
The IObjectSpaceProvider is a provider/creator of IObjectSpace entities, which also manages which business types these IObjectSpace are supposed to work with, how to set up the underlying connection to the database, create and update it and other low level data access options.

Image may be NSFW.
Clik here to view.


An XafApplication can use one or several IObjectSpaceProvider objects at the same time, and you can access this information through the XafApplication.ObjectSpaceProvder or XafApplication.ObjectSpaceProviders properties. Check out these help links to learn more on how to plug in custom IObjectSpaceProvider objects a well.

There are several built-in implementations of the IObjectSpaceProvider and IObjectSpace interfaces in our framework, which are usually specific to a target ORM (Entity Framework or XPO). I suggest you check out the source code of the default framework classes to better understand the role of the IObjectSpaceProvider:

...\DevExpress.ExpressApp.Xpo\XPObjectSpaceProvider.cs
...\DevExpress.ExpressApp.EF\EFObjectSpaceProvider.cs 

Typical customization considerations
You may want to provide a fully custom IObjectSpaceProvider implementation or inherit from the built-in implementors when you want to customize how data access is performed for a chosen ORM.
Below is a list of typical scenarios where a custom IObjectSpaceProvider may be required:

1. How to use XPO caching in XAF 
2. How to prevent altering the legacy database schema when creating an XAF application 
3. How to connect to remote data store and configure WCF end point programmatically 
4. How do I map persistent classes to another schema, e.g. other than the default "dbo" in MS SQL Server?
5. How to use a custom ObjectSpace throughout the application by handling the CreateCustomObjectSpaceProvider event? 
6. How to connect different ORM data models to several databases within a single application
7. How to customize the Object Space behavior in XPO-based XAF applications
8. How to customize the UnitOfWork behavior in XPO-based XAF applications

In most cases, it is not required to implement the IObjectSpaceProvider interface from scratch since you can inherit from existing implementors or customize/just their parts.


XPO-specific customizations

1. Implementing IXpoDataStoreProvider

For instance, in XPO one of such replaceable parts is the IXpoDataStoreProvider interface, which enables you to provide a custom or configured IDataStore object, which is used for underlying data access with this ORM:

[C#]
publicinterfaceIXpoDataStoreProvider{IDataStoreCreateWorkingStore(outIDisposable[]disposableObjects);IDataStoreCreateUpdatingStore(outIDisposable[]disposableObjects);IDataStoreCreateSchemaCheckingStore(outIDisposable[]disposableObjects);stringConnectionString{get;}}

 

In its turn, XAF provides several ready to use implementations of this interface for most popular scenarios: 

1. ConnectionDataStoreProvider - can provide IDataStore by the IDbConnection object;

2. ConnectionStringDataStoreProvider - can provide IDataStore by just connecting string information;

3. MemoryDataStoreProvider - DataSet based in-memory IDataStore providers.


Technically, such an IXpoDataStoreProvider part is passed into the XPObjectSpaceProvider constructor as a parameter, which means that you can just customize it instead of re-implementing the whole XPObjectSpaceProvider logic:

[C#]
//In your XafApplication descendant class (e.g., in the YourSolutionName.Win/WinApplication.cs file).protectedoverridevoidCreateDefaultObjectSpaceProvider(CreateCustomObjectSpaceProviderEventArgsargs){args.ObjectSpaceProvider=newXPObjectSpaceProvider(newMyIXpoDataStoreProvider(args.ConnectionString,args.Connection,false),true);args.ObjectSpaceProviders.Add(newNonPersistentObjectSpaceProvider(TypesInfo,null));}

You can find IXpoDataStoreProvider implementation examples in the following articles:
How to use XPO caching in XAF
How to prevent altering the legacy database schema when creating an XAF application

Refer to the ...\DevExpress.ExpressApp.Xpo\XPObjectSpaceProvider.cs file within the XAF source code to better understand the role of this part.

2. Handling the DataStoreCreated event of ConnectionDataStoreProvider and ConnectionStringDataStoreProvider 
Instead of creating your own IXpoDataStoreProvider  from scratch, it is often simpler to explicitly create a ConnectionDataStoreProvider or ConnectionStringDataStoreProvider instance (an IXpoDataStoreProvider implementer) and subscribe to its DataStoreCreated event (available starting with version 17.2).  The event arguments (DataStoreCreatedEventArgs) expose the DataStore and Destination parameters that provide access to the current data store and its type (SchemaChecking,  Updating or Working). Refer to the How do I map persistent classes to another schema, e.g. other than the default "dbo" in MS SQL Server?  example for more details.

 

3. Overriding XPO connection or database providers

To learn more on this approach, check out the Database Systems Supported by XPO help topic and How to create a custom XPO connection provider and then use it in an XAF application article in particular.  To learn more on customizing data access settings for XPO, please refer to the corresponding product documentation: Data Access Layer.



See Also:
Can I connect an XAF application to a custom data source (Web service, OData service, NoSQL database, etc.)?

Question Comments

Added By: Rejoice Supsup at: 9/16/2015 11:33:05 AM    

Is this intended to contain an empty example resource?

Added By: Dennis (DevExpress Support) at: 9/16/2015 11:46:15 AM    

Yes. This article originally contained an example, but it is now more like a KB article.

Added By: Rejoice Supsup at: 9/16/2015 12:00:10 PM    

Thank you for the quick reply. But I thought this might be misleading since it's categorized as an example. Should I expect that you're be providing an example in the future? If I may suggest, what about 2 databases:

#1 - Departments and Employees
#2 - Customers and Orders

Where #1 is integrated with the Security Module and #2 (used by XAF Win Forms) to manage CRM data but will be authenticated via DB #1.

Added By: Dennis (DevExpress Support) at: 9/16/2015 12:16:34 PM    

The category is to be changed in the future as the main purpose of this article is to describe the main concepts.
There are already multiple examples mentioned in this article - see under the "Typical customization considerations" section (no plans for new examples so far). I hope you find them helpful to implement your particular scenario. Should you have any further difficulties with your own implementation, please submit a separate ticket and attach your sample showing what you tried to do and what did not work as expected. Thanks.

How to customize resource headers to display custom text and images

To display an image or text in the resource header, create a custom template and assign it to the ViewBase.ResourceHeaderContentTemplate property. 
The ResourceItem object has no property that contains an associated image, so use custom fields to obtain an image when necessary.
The resulting application is shown below.
Image may be NSFW.
Clik here to view.

How to open Excel files in GridControl

Our GridControl, as well as any standard control, does not directly work with physical files. There are many reasons for this. For example, it is not possible to get notifications when some part of a physical file is changed. Thus, it will be necessary to reload the entire file each time the GridControl content needs to be refreshed. Also, to save each change made in GridControl, it will be necessary to access this file again. Thus, dealing with physical files directly will be very slow.

Starting with version 15.2, ExcelDataSource is available, which allows extracting data from Microsoft Excel workbooks or CSV files. For more information about it, please review the Binding to Excel Data Sources documentation topic.

If you are using an older version, you can populate a DataSet with data from an Excel file and then bind the grid control to this DataSet. To do this, you can use the Microsoft OLE DB Provider for Microsoft Jet. 
These solutions are described in the following articles:

Microsoft OLE DB Provider for Microsoft Jet

Import Excel File to DataSet - CodeProject

 

This example demonstrates this approach in action.

How to handle a double-click on a grid row or cell

This example demonstrates how to handle a double-click on a grid row or cell. Since GridControl can be in one of two states - editable or non editable, it is necessary to use different approaches for each state. Please refer to the How to handle a double-click on a grid row or cell article to learn implementation details.

Question Comments

Added By: Tom Woods at: 8/9/2012 12:22:42 PM    

This worked perfectly for me. However, now the double-click on the column width indicator is not functioning and I have no idea how to get it back! Basically, I stripped this down to just this:

Private Sub GridViewHistory_DoubleClick(sender As Object, e As System.EventArgs) Handles GridViewHistory.DoubleClick
        Dim view As GridView = CType(sender, GridView)
        Dim pt As Point = view.GridControl.PointToClient(Control.MousePosition)
        Dim info As GridHitInfo = view.CalcHitInfo(pt)

        If info.InRow OrElse info.InRowCell Then
            GridControlHistory_Click(sender, New System.EventArgs)
            Dim colView As ColumnView = GridControlHistory.FocusedView
            Dim rhFound As Integer = view.FocusedRowHandle
            If rhFound >= 0 Then
                Call Edit_Record(colView, rhFound)
            End If
        Else
            'NEED CODE HERE TO REPLACE THE COLUMN DOUBLECLICK EVENT

        End If

    End Sub

Any ideas?

How to create edit form templates dynamically

This example illustrates how to add editors within EditFormTemplateContainer of ASPxGridView programmatically by implementing the ITemplate interface.
 
Custom editors are added onto the edit form by creating a custom edit form template. In this example, a template is created as a descendant of the ITemplate interface in the EditFormTemplate.cs file. The template is populated with content using the InstantiateIn method. The Update and Cancel edit form's regular buttons are kept within the custom edit form using Template Replacements (the ASPxGridViewTemplateReplacements object).
 
The edit form template is attached to the grid in the Page Load event handler. The edit form template's content can be accessed at runtime using the FindEditFormTemplateControl method. It receives a control's ID as a parameter and returns the control if it exists within the edit form template.

See also:
ASPxGridView - How to load UserControl within EditFormTemplate at runtime

Question Comments

Added By: Esa Niemi at: 10/28/2015 7:17:19 AM    

Could you add some comments? It takes unnecessarily long from a devexp-noob to parse what is going on.

Added By: Lisa Bencic at: 11/28/2017 8:05:23 AM    This whole topic fails when you have a detail inside a master, you cannot reference the (child) grid view during Page Load like that.   Most solutions I am looking at (to Hide a field during Edit but not during New) do not work for that reason.Added By: Lex (DevExpress Support) at: 11/28/2017 9:49:38 PM    

Hello Lisa,

I've created a separate ticket on your behalf (T581934: ASPxGridView - Master-Detail - How to hide a certain field in the detail grid's edit form when it is created at runtime). It has been placed in our processing queue and will be answered shortly.

How to dynamically send a report via e-mail as a PDF

This example illustrates how to automatically send a report via e-mail. To do this, a report should first be exported into one of the available formats. In this example, a report is exported to PDF, since this format provides the best output quality (the PDF result is as close to a report's print result as possible).

See also:
How to send a report as HTML in an email body

Question Comments

Added By: MohammedFarooq at: 10/20/2015 1:11:44 PM    

Hi,
I am getting the following error when the button is clicked. For your information, i am executing this logic in XAF viewcontroller SimpleAction button execute event

Error sending a report.
System.Exception: Null object cannot be converted to a value type. ---> System.Exception: Null object cannot be converted to a value type. ---> System.InvalidCastException: Null object cannot be converted to a value type.
at System.Convert.ChangeType(Object value, Type conversionType, IFormatProvider provider)
at System.Convert.ChangeType(Object value, Type conversionType)
at DevExpress.XtraReports.UI.XRSubreport.ApplyParameterBindings()
at DevExpress.XtraReports.UI.XRSubreport.OnBeforePrint(PrintEventArgs e)
at DevExpress.XtraReports.UI.XRControl.GetPrintableBrick(XRWriteInfo writeInfo)
at DevExpress.XtraReports.UI.XRControl.WriteContentTo(XRWriteInfo writeInfo)
at DevExpress.XtraReports.UI.Band.GenerateContent(DocumentBand docBand, Int32 rowIndex, Boolean fireBeforePrint)
at DevExpress.XtraReports.UI.Band.GenerateContentAndDecompose(DocumentBand docBand, Int32 rowIndex, Boolean fireBeforePrint)
at DevExpress.XtraReports.UI.Band.CreateDocumentBand(Int32 rowIndex, RootDocumentBand rootDocBand, PageBuildInfo pageBuildInfo)
at DevExpress.XtraReports.UI.DetailBand.CreateDocumentBand(Int32 rowIndex, Int32 rowCount, RootDocumentBand rootDocBand, PageBuildInfo pageBuildInfo)
at DevExpress.XtraReports.Native.Printing.DetailWriterBase.WriteDetailCore(PageBuildInfo pageBuildInfo)
at DevExpress.XtraReports.Native.Printing.DetailWriterBase.Write(DocumentBand rootBand, PageBuildInfo pageBuildInfo)
at DevExpress.XtraReports.Native.Printing.DocumentBuilder.GetBand(DocumentBand rootBand, PageBuildInfo pageBuildInfo)
at DevExpress.XtraPrinting.Native.DocumentBand.GetBand(PageBuildInfo pageBuildInfo)
at DevExpress.XtraPrinting.Native.PageHeaderFooterRowBuilderBase.CanProcessDetail(DocumentBand rootBand, PageBuildInfo pageBuildInfo)
at DevExpress.XtraPrinting.Native.PageRowBuilderBase.FillPageForBands(DocumentBand rootBand, RectangleF bounds, ProcessBandsDelegate process)
at DevExpress.XtraPrinting.Native.PageRowBuilderBase.FillReportDetails(DocumentBand rootBand, RectangleF bounds)
at DevExpress.XtraPrinting.Native.PageHeaderFooterRowBuilderBase.FillReportDetailsAndFooter(DocumentBand rootBand, RectangleF bounds)
at DevExpress.XtraPrinting.Native.PageRowBuilderBase.FillPage(DocumentBand rootBand, RectangleF bounds)
at DevExpress.XtraPrinting.Native.PageRowBuilderBase.FillPageRecursive(DocumentBand rootBand, DocumentBand docBand, RectangleF bounds)
at DevExpress.XtraPrinting.Native.PageHeaderFooterRowBuilderBase.FillPageRecursive(DocumentBand rootBand, DocumentBand docBand, RectangleF bounds)
at DevExpress.XtraPrinting.Native.PageRowBuilderBase.FillPageForBandCore(DocumentBand rootBand, RectangleF bounds, RectangleF newBounds)
at DevExpress.XtraPrinting.Native.PageRowBuilderBase.FillPageForBand(DocumentBand rootBand, RectangleF bounds, RectangleF newBounds)
at DevExpress.XtraPrinting.Native.PageRowBuilderBase.FillPageForBands(DocumentBand rootBand, RectangleF bounds, ProcessBandsDelegate process)
at DevExpress.XtraPrinting.Native.PageRowBuilderBase.FillReportDetails(DocumentBand rootBand, RectangleF bounds)
at DevExpress.XtraPrinting.Native.PageHeaderFooterRowBuilderBase.FillReportDetailsAndFooter(DocumentBand rootBand, RectangleF bounds)
at DevExpress.XtraPrinting.Native.PageRowBuilderBase.FillPage(DocumentBand rootBand, RectangleF bounds)
at DevExpress.XtraPrinting.Native.PageRowBuilderBase.FillPageRecursive(DocumentBand rootBand, DocumentBand docBand, RectangleF bounds)
at DevExpress.XtraPrinting.Native.PageHeaderFooterRowBuilderBase.FillPageRecursive(DocumentBand rootBand, DocumentBand docBand, RectangleF bounds)
at DevExpress.XtraPrinting.Native.PageRowBuilderBase.FillPageForBandCore(DocumentBand rootBand, RectangleF bounds, RectangleF newBounds)
at DevExpress.XtraPrinting.Native.PageRowBuilderBase.FillPageForBand(DocumentBand rootBand, RectangleF bounds, RectangleF newBounds)
at DevExpress.XtraPrinting.Native.PageRowBuilderBase.FillPageForBands(DocumentBand rootBand, RectangleF bounds, ProcessBandsDelegate process)
at DevExpress.XtraPrinting.Native.PageRowBuilderBase.FillReportDetails(DocumentBand rootBand, RectangleF bounds)
at DevExpress.XtraPrinting.Native.PageHeaderFooterRowBuilderBase.FillReportDetailsAndFooter(DocumentBand rootBand, RectangleF bounds)
at DevExpress.XtraPrinting.Native.PageRowBuilderBase.FillPage(DocumentBand rootBand, RectangleF bounds)
at DevExpress.XtraPrinting.Native.PageRowBuilderBase.FillPageRecursive(DocumentBand rootBand, DocumentBand docBand, RectangleF bounds)
at DevExpress.XtraPrinting.Native.PageHeaderFooterRowBuilderBase.FillPageRecursive(DocumentBand rootBand, DocumentBand docBand, RectangleF bounds)
at DevExpress.XtraPrinting.Native.PageRowBuilderBase.FillPageForBandCore(DocumentBand rootBand, RectangleF bounds, RectangleF newBounds)
at DevExpress.XtraPrinting.Native.PageRowBuilderBase.FillPageForBand(DocumentBand rootBand, RectangleF bounds, RectangleF newBounds)
at DevExpress.XtraPrinting.Native.PageRowBuilderBase.FillPageForBands(DocumentBand rootBand, RectangleF bounds, ProcessBandsDelegate process)
at DevExpress.XtraPrinting.Native.PageRowBuilderBase.FillReportDetails(DocumentBand rootBand, RectangleF bounds)
at DevExpress.XtraPrinting.Native.PageHeaderFooterRowBuilderBase.FillReportDetailsAndFooter(DocumentBand rootBand, RectangleF bounds)
at DevExpress.XtraPrinting.Native.PageRowBuilderBase.FillPage(DocumentBand rootBand, RectangleF bounds)
at DevExpress.XtraPrinting.Native.PageRowBuilderBase.FillPageRecursive(DocumentBand rootBand, DocumentBand docBand, RectangleF bounds)
at DevExpress.XtraPrinting.Native.PageHeaderFooterRowBuilderBase.FillPageRecursive(DocumentBand rootBand, DocumentBand docBand, RectangleF bounds)
at DevExpress.XtraPrinting.Native.PageRowBuilderBase.FillPageForBandCore(DocumentBand rootBand, RectangleF bounds, RectangleF newBounds)
at DevExpress.XtraPrinting.Native.PageRowBuilderBase.FillPageForBand(DocumentBand rootBand, RectangleF bounds, RectangleF newBounds)
at DevExpress.XtraPrinting.Native.PageRowBuilderBase.FillPageForBands(DocumentBand rootBand, RectangleF bounds, ProcessBandsDelegate process)
at DevExpress.XtraPrinting.Native.PageRowBuilderBase.FillReportDetails(DocumentBand rootBand, RectangleF bounds)
at DevExpress.XtraPrinting.Native.PageHeaderFooterRowBuilderBase.FillReportDetailsAndFooter(DocumentBand rootBand, RectangleF bounds)
at DevExpress.XtraPrinting.Native.PageRowBuilderBase.FillPage(DocumentBand rootBand, RectangleF bounds)
at DevExpress.XtraPrinting.Native.PageBuildEngine.Build()
at DevExpress.XtraPrinting.Native.PageBuildEngine.BuildPages(DocumentBand rootBand, Boolean clearGroupingInfo)
--- End of inner exception stack trace ---
at DevExpress.XtraPrinting.PrintingSystemBase.OnCreateDocumentException(ExceptionEventArgs args)
at DevExpress.XtraPrinting.Native.PageBuildEngine.RaiseCreateDocumentException(Exception exception)
at DevExpress.XtraPrinting.Native.PageBuildEngine.BuildPages(DocumentBand rootBand, Boolean clearGroupingInfo)
at DevExpress.XtraPrinting.Native.DocumentHelper.BuildPagesCore()
at DevExpress.XtraPrinting.Native.DocumentHelper.BuildPages()
at DevExpress.XtraPrinting.Native.PrintingDocument.BuildPages()
at DevExpress.XtraPrinting.Native.PrintingDocument.End(Boolean buildPagesInBackground)
at DevExpress.XtraPrinting.PrintingSystemBase.End(Boolean buildPagesInBackground)
at DevExpress.XtraReports.UI.XtraReport.CreateDocumentCore(PrintingSystemBase ps, Single progressRange, Boolean buildPagesInBackground)
at DevExpress.XtraReports.UI.XtraReport.CreateDocument(Single progressRange, Boolean buildPagesInBackground, Boolean suppressClearDataContext)
at DevExpress.XtraReports.UI.XtraReport.TryCreateDocument(Single progressRange, Boolean buildPagesInBackground, Boolean suppressClearDataContext)
--- End of inner exception stack trace ---
at DevExpress.XtraPrinting.PrintingSystemBase.OnCreateDocumentException(ExceptionEventArgs args)
at DevExpress.XtraReports.UI.XtraReport.TryCreateDocument(Single progressRange, Boolean buildPagesInBackground, Boolean suppressClearDataContext)
at DevExpress.XtraReports.UI.XtraReport.CreateIfEmpty(Single progressRange, Boolean buildPagesInBackground)
at DevExpress.XtraReports.UI.XtraReport.ExportToPdf(Stream stream, PdfExportOptions options)
at DevExpress.XtraReports.UI.XtraReport.ExportToPdf(Stream stream)
at Solution6.Module.vcPayroll.SimpleAction1_Execute(Object sender, SimpleActionExecuteEventArgs e) in E:\My Docs\Projects\Solution6\Code\Solution6.Module\BusinessObjects\10 Payroll\Payroll Run\vcPayroll.vb:line 179

Added By: MohammedFarooq at: 10/20/2015 1:12:27 PM    

The error happens at this line

report.ExportToPdf(mem)

Added By: Ingvar (DevExpress Support) at: 10/21/2015 1:28:10 AM    

Hello,

To process your recent post more efficiently, I created a separate ticket on your behalf: T302655: NullReferenceException when trying to apply solution described in E16. This ticket is currently in our processing queue. Our team will address it as soon as we have any updates.

Added By: Eduardo Ramirez at: 2/8/2018 6:49:06 AM    Dear support,

I am sending emails without problems from report in PDF format. My question is, where are the email sent?
I have looked for in sent items folder and it is missing.

I use the example routine and in FROM and TO fields I use my email address. I receive the email, but I not found the email sended.

I use Outlook with Office 365 mail.

King regards.
Eduardo.

How to bind GridControl to a collection of Business Objects

This example binds a GridControl to a collection of custom Record objects and demonstrates the following features:
- Assigning an inplace editor (combo box) to a column
- Specifying a column's display name and data format by applying DataAnnotation attributes to Record class properties
- Two ways of changing cell values - at the data source and grid level.
- Highlighting cell values that meet a condition

How to create and populate an unbound column

GridView does not cache values of an unbound column, because it is impossible to determine when the cache should be cleared automatically. GridView just displays values provided by the CustomUnboundColumnData event. So, to display a specific value in a cell, you need to pass a corresponding value to the e.Value parameter based on a processed column and row. What you return as the e.Value parameter is what is displayed in GridView. Each time a cell needs to be updated, the CustomUnboundColumnData event is called.

This example demonstrates how a simple caching mechanism can be implemented. In this project, you can perform all supported operations with GridView, such as sorting/deleting/adding records, and the unbound column will display proper values. This is because values of the ID column are used as key values. This column is read-only and contains only unique values. So, rows can be always identified.

You can also use the  GridColumn.UnboundExpression property to specify and unbound expression. Please refer to the Unbound Columns help article for additional information.

Question Comments

Added By: DevInfox at: 11/24/2012 3:13:02 PM    

When using code I get following error
Error     1     'InitializeComponent' is not declared. It may be inaccessible due to its protection level.     C:\Users\Boris\AppData\Local\Temporary Projects\WindowsApplication1\Form1.vb     32     13     WindowsApplication1
Error     2     'gridControl1' is not declared. It may be inaccessible due to its protection level.     C:\Users\Boris\AppData\Local\Temporary Projects\WindowsApplication1\Form1.vb     34     13     WindowsApplication1
Error     3     'gridView1' is not declared. It may be inaccessible due to its protection level.     C:\Users\Boris\AppData\Local\Temporary Projects\WindowsApplication1\Form1.vb     38     37     WindowsApplication1
Error     4     Handles clause requires a WithEvents variable defined in the containing type or one of its base types.     C:\Users\Boris\AppData\Local\Temporary Projects\WindowsApplication1\Form1.vb     44     156     WindowsApplication1
 Please advice

Added By: Mathias Tenaye Sahile at: 12/24/2014 12:54:27 AM    

i tried but was not sucessfull when is this
   Private Sub gridView1_CustomUnboundColumnData(ByVal sender As Object, ByVal e As DevExpress.XtraGrid.Views.Base.CustomColumnDataEventArgs) Handles gridView1.CustomUnboundColumnData
           If e.IsGetData Then
               e.Value = _Cache.GetValue(e.Row)
           End If
           If e.IsSetData Then
               _Cache.SetValue(e.Row, e.Value)
           End If
       End Sub
called do and how

Added By: Olga (DevExpress Support) at: 12/24/2014 2:18:48 AM    Hello,
As I can see, you've created a separate ticket on this subject. I've moved your comment there. Let's continue our discussion in that thread.Added By: Paul Riddell at: 1/5/2015 9:44:49 AM    

Hi are there any examples of this using an xpcollection of xpobjects as the datasource?

Added By: Dimitros (DevExpress Support) at: 1/6/2015 3:24:00 AM    

Hello Johnathon ,

To process your recent post more efficiently, I created a separate ticket on your behalf: T193371: Unbound column - how to use with XPCollection. This ticket is currently in our processing queue. Our team will address it as soon as we have any updates.

Added By: Dirk Dumon 1 at: 5/28/2015 12:43:44 AM    

Hi, I tried implementing this but the method gridView1_CustomUnboundColumnData is never triggered with IsSetData = true.
Only IsGetData is triggered.
In this regard, I found https://www.devexpress.com/Support/Center/Question/Details/CB65344
So, is this sample not correct or is there a way to get the IsSetData to work?

Added By: Nadezhda (DevExpress Support) at: 5/28/2015 2:26:29 AM    

Hello,

To process your recent post more efficiently, I created a separate ticket on your behalf: How to set the CustomColumnDataEventArgs.IsSetData property to true . This ticket is currently in our processing queue. Our team will address it as soon as we have any updates.

Added By: Nguyen Bac 1 at: 5/9/2016 10:08:51 PM    I have a problem with MyCach class. I don't know how to write this class. 
Please!
Added By: Andrew Ser (DevExpress Support) at: 5/10/2016 2:18:09 AM    Hello,

Here is an example illustrating the implementation of the MyCache class. Select it in the combo box as shown below:


Image may be NSFW.
Clik here to view.

How to set the cell color using different approaches

This example illustrates approaches to set the color of a time cell in a scheduler grouped by resource.
1. Each resource can have its own color specified by the ResourceItem.Color property. Uncomment two lines in the MainWindow's XAML to assign the resource color mapping, so that each resource obtains its color from the data source.
2. Use a custom resource brush schema. Create a ResourceBrushSchemaCollection object in MainWindow's XAML resources and assign it to the  SchedulerControl.ResourceBrushSchemas property.
3. Create a CellControl's data template, define a cell style and assign the style to the appropriate property of the desired view:
- Day view, Work-Week view, Week view - use the DayViewBase.AllDayCellStyle and DayViewBase.CellStyle properties;
- Month view - use the MonthView.CellStyle property;
- Timeline view - use the TimelineView.CellStyle property.
The picture below demonstrates a custom cell style and template applied to the selected cells of the resource with ID=1.  A custom data template displays the time interval contained in the cell's data context.
Image may be NSFW.
Clik here to view.

TreeList - How to implement node reordering

Currently, the TreeList extension only allows node insertion (a modification of the current node's parent node). 
This example demonstrates how to implement node reordering and also provides the implementation of custom reorder/insert icons. 

Here is how you can implement this scenario:
- Get all of the sibling nodes of the node that is currently being dragged and calculate its bounds in the client-side ASPxClientTreeList.StartDragNode event handler.
- Ensure that the mousemove handler is attached to the document object. In the client-side mousemove event handler, check whether it is possible to reorder/insert nodes and change the reorder/insert image.
- In the client-side ASPxClientTreeList.EndDragNode event handler, get the e.htmlEvent object and see if reordering is possible. If so, set the e.cancel property to false and perform a custom callback to the TreeList extension.


In order to check whether it is possible to reorder nodes, iterate through the neighboring nodes' bounds you've saved in the StartDragNode event handler. In order to get the current cursor position, use the ASPx.Evt.GetEventX and ASPx.Evt.GetEventY methods. 

In order to get the drag & drop image, use the GetDragAndDropNodeImage method of the ASPxClientTreeList object. Note that this is private API, so we do not guarantee that we will not change it in our further releases. Even though in the case of the GetDragAndDropNodeImage method it is hardly possible that we will change it, I still encourage you to test this solution while upgrading to the next releases.

 

Node reorder functionality limitation: It is not possible to keep a custom order of the nodes when the control is sorted by any column. Thus, it is necessary to disable the sorting functionality via the TreeListSettings.SettingsBehavior.AllowSort property.

See also: 
How to reorder ASPxTreeList sibling nodes, using buttons or drag-and-drop
ASPxTreeList - How to implement node reordering - WebForms Version

How to make a grid have no focused row

This example demonstrates how to setup a grid so that it initially doesn't have a focused row. The focused row becomes highlighted once you click any.

If you want not to highlight the focused row at all, remove the code from the GridFocusedRowHighlightHelper.View_MouseDown event handler. Note that you can manually toggle the focused row indication by using the GridFocusedRowHighlightHelper.SetFocusedRowIndication method.


The example for older versions demonstrates how to setup a grid so that it doesn't have a focused row at all.

See Also:
How to remove row selection highlighting when the GridControl loses focus

ASPxTreeList - How to implement node reordering

Currently, the ASPxTreeList control only allows node insertion (a modification of the current node's parent node). 
This example demonstrates how to implement node reordering and also provides the implementation of custom reorder/insert icons. 

Here is how you can implement this scenario:
- Get all of the sibling nodes of the node that is currently being dragged and calculate its bounds in the client-side ASPxClientTreeList.StartDragNode event handler.
- Ensure that the mousemove handler is attached to the document object. In the client-side mousemove event handler, check whether it is possible to reorder/insert nodes and change the reorder/insert image.
- In the client-side ASPxClientTreeList.EndDragNode event handler, get the e.htmlEvent object and see if reordering is possible. If so, set the e.cancel property to false and perform a custom callback to the ASPxTreeList control via the ASPxClientTreeList.PerformCallback method.


In order to check whether it is possible to reorder nodes, iterate through the neighboring nodes' bounds you've saved in the StartDragNode event handler. In order to get the current cursor position, use the ASPx.Evt.GetEventX and ASPx.Evt.GetEventY methods. 

In order to get the drag & drop image, use the GetDragAndDropNodeImage method of the ASPxClientTreeList object. Note that this is private API, so we do not guarantee that we will not change it in our further releases. Even though in the case of the GetDragAndDropNodeImage method it is hardly possible that we will change it, I still encourage you to test this solution while upgrading to the next releases.

 

Node reorder functionality limitation: It is not possible to keep a custom order of the nodes when the control is sorted by any column. Thus, it is necessary to disable the sorting functionality via the ASPxTreeList.SettingsBehavior.AllowSort property.

See also: 
How to reorder ASPxTreeList sibling nodes, using buttons or drag-and-drop
TreeList - How to implement node reordering - MVC Version

How to show files preview as a thumbnail in ASPxFileManager

This example is a simplified implementation of the DXDocs demo that illustrates how to create a file thumbnail based on the first page of the document. 
The ASPxFileManager.CustomThumbnail event is used for defining a custom value for the FileManagerItem.ThumbnailUrl property. Since this solution does not provide a cashing mechanism, previews are generated on each request. To increase application performance, refer to the FileSystemService class of the DXDocs demo.

Important Note:

The Document Server product license is required for using this approach. Please refer to the Subscriptions page for more information.


How to add wait indicator to your application

To control the WaitIndicator control's visibility, use the DeferedVisibility property. As for changing WaitIndicator's properties, it is a common WPF control and you can change its properties in code behind or using bindings. You can read more about the bindings here:  Data Binding(WPF).

How to bind an ASP.NET MVC GridView extension to a table with an unknown schema using Custom Data Binding and XPO

Disclaimer:
This example demonstrates an edge-case scenario and uses XPO in an uncommon way. Refer to the following articles for XPO best practices:
How to use XPO in an ASP.NET (Web) application
How to bind editors to XPO objects in an ASP.NET MVC application

Targets:
The approach demonstrated in this example can be used when you need to take advantage of the partial data loading feature, but cannot use statically declared business models mapped to the database. This approach can be used to support adding/removing database columns without modifying the application code, to implement a generic View consuming data from an arbitrary table (or even database) selected by the user, or to implement a SaaS application.

Prerequisites:
This example is based on the following technologies:
1. eXpress Persistent Objects (aka XPO) are used as a data access layer. Refer to the tutorials in our online documentation to get started with XPO: Getting Started.
2. XPO supports dynamic mapping to the database tables without declaring any classes. Refer to this Knowledge Base article to learn more about this functionality: How to create persistent metadata on the fly and load data from an arbitrary table.
3. Our GridView component for ASP.NET MVC platform has an API that allows you to populate a grid with data manually taking into account the current grid state (filtering, sorting, grouping) - Custom Data Binding.
4. XPO provides components that can be used to load objects without knowing their types at compile time (XPCollection) or building complex queries with grouping, filtering, sorting and data aggregation (XPView).

Refer to our online documentation to understand concepts used in this example.

Implementation details:

1. This example extends a standard approach of connecting an ASP.NET application to an XPO data store described in this article: How to use XPO in an ASP.NET (Web) application. In this scenario, the persistent classes schema can be changed at run time. To address this requirement, it is necessary to create a separate Data Access Layer for each user, instead of sharing a single ThreadSafeDataLayer instance between all users as it recommended to do in regular scenarios. Refer to the XPO\XpoHelper.cs(vb) file for implementation details.
2. To handle the concurrent access to a data store, this example uses the DataStorePool component. XPO automatically creates DataStorePool when the connection string contains the special parameter. The XpoDefault.GetConnectionPoolString method is used to prepare such connection string.
3. The GetNewSession and GetNewUnitOfWork methods implemented in the extended XpoHelper class accept an XPDictionary instance as a last parameter. XPDictionary provides metadata information used to map persistent objects to database tables. In the example, the XPDictionary instance is prepared in the XPO\DatabaseSchemaHelper.cs(vb) file. This implementation is intended for demonstration purposes only. In real projects, it should be replaced with a custom implementation integrated with the application architecture and business requirements.
4. The XPO\XpoBindingHandlers.cs(vb) file contains a universal class that can be used in real projects without modifications. It provides the implementation of typed method delegates required to calling to a grid view model's GridViewModel.ProcessCustomBinding method. The usage is demonstrated in the Controllers\OrdersController.cs(vb) file.

How to use:

To add this functionality to an existing ASP.NET MVC project, do the following:
1. Copy the XPO\XpoHelper.cs(vb) file to your project. If the project already contains a similar helper class copied from the K18061 article, you can replace it or use both the implementations together.
2. Add required connection strings to your Web.config file. Refer to the Microsoft documentation to learn more about the <connectionStrings> configuration section: Creating a Connection String and Working with SQL Server LocalDB, SQL Server Connection Strings for ASP.NET Web Applications. If the application uses a database other than MS SQL Server, it is necessary to add a special parameter to a connection string. Refer to the following article for details: How to create a correct connection string for XPO providers.
3. Copy the XPO\XpoBindingHandlers.cs(vb) file to your project.
4. Using examples provided in the XPO\DatabaseSchemaHelper.cs(vb) file and the K18482 article, implement a helper class that builds metadata to map persistent objects to specific tables according to your business requirements.

Use the XpoBindingHandler class in your Controllers the same way as it is demonstrated in the Controllers\OrdersController.cs(vb) file. This class is independent from other parts of the project and can be re-used without modifications.

How to bind dictionaries to the Spell Checker in MVVM applications

Bootstrap Controls for ASP.NET Web Forms - How to implement a responsive side bar

This example shows how to implement a simplified version of the responsive side bar from our online Bootstrap demos.
The required layout is implemented in the following files:

1. "Shared/Site.master"
This is a Master Page where the basic web site layout is implemented. It also contains the side bar element:

[ASPx]
<uc:SideBarrunat="server"id="SideBar"/>

 

To enable responsive layout, add references to the following styles:
- bootstrap.min.css;
- navBarLayout.css - this file includes required CSS rules for this layout;

Also, the following scripts are required:
- jQuery;
- site.js - this file contains the required JavaScript code.
You can also include the desired icon font there.

2. "Shared/SideBar.ascx"
This is a User Control which implements the side bar element. It is created using the BootstrapTreeView control. Make sure that the ID of this control is set to "navTreeView" and the ClientIDMode is set to "static": this ID is used in the CSS classes. To collapse the side bar like in our demos, handle the client-side BootstrapClientTreeView.NodeClick event and call the onSideBarNodeClick function in it. This function hides the side bar depending on window size.

How to update the parameter value when the item's master filter state is changed

This example illustrates how to pass filter values to a parameter. The initial master filter state is set manually on page loading.

To obtain changed master filter values, handle the ASPxClientDashboard.ItemMasterFilterStateChanged event. Pass these values to the dashboard parameter using the ASPxClientDashboard.GetParameters method. 
To assign default master filter values, use the Dashboard State. Refer to the Web Dashboard - How to specify a dashboard state manually in code example for more information about this approach.

See also:
How to specify dashboard parameter values on the client side in the ASP.NET Dashboard Control

Viewing all 7205 articles
Browse latest View live


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