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

How to create a DateEdit descendant that will allow date unit selection, and multiple dates and periods selection

$
0
0

This example shows how to create a DateEdit descendant that will allow date unit selection, and multiple dates and periods selection.

See Also:
Forcing DateEdit to select multiple dates and periods

Question Comments

Added By: Torr Wash at: 12/7/2015 11:52:55 PM    

Example 15.2.3 absolutely stupid and does not correspond to the functional old version!
How to make DateEdit function as DatePeriodEdit?
You have successfully broke what worked for several years.
As it is now, edit  Period or PeriodSet ??
DatePeriodEdit is now impossible to compile because you have cut the necessary classes!

Added By: Nadezhda (DevExpress Support) at: 12/8/2015 7:01:55 AM    

Hello Torr,

We have introduced a calendar control in version 15.2 - CalendarControl. This control has the SelectionMode property.
Now, this calendar is used in DateEdit's popup. Thus, SelectedMode is available in the RepositoryItemDateEdit class. However, there is no way to obtain selection of multiple dates for DateEdit.EditValue at the moment.
If you wish to get or set a selected range, you can use CalendarControl.SelectedRanges. I have modified the example to illustrate it.
Do not hesitate to contact us if you need any further assistance. 


How to handle the Back button click

$
0
0

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;});


Starting with 14.2, use the following code:

[JScript]
Application1.app.currentViewModel = null; Application1.app.on("viewShown", function(e){ Application1.app.currentViewModel = e.viewInfo.model;}); Application1.app.on("navigatingBack", 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.

Question Comments

Added By: Paul Haffner at: 2/20/2015 10:18:14 AM    

This works fine in the emulator, but when I run it on a real device running Windows Phone 8.1, the event is not triggered. Instead the app terminates immediately when the hardware back button is pressed. I am using dx 14.2.

Added By: Marion (DevExpress Support) at: 2/23/2015 1:00:27 AM    @Paul,
We will process this question in the context of the following thread:
T211574: Windows Phone hardware back button terminates app

How to perform drag-and-drop operation in a custom manner

$
0
0

This example illustrates how to perform the drag-and-drop operation in case of a ListBox drag-and-drop source. Since there is no built-in capability to accomplish this task, you should perform the drag-and-drop operation in a custom manner. To do this, use the following RichEditControl events: DragEnter, DragOver, DragDrop. Most part of the work is performed in the DragOver event handler. Here, you should update the RichEditControl.Document.CaretPosition property value according to the current mouse position (use the approach from the How to: Obtain the Document Position under the Mouse Cursor) help section for this purpose). Also, you might want to draw a custom insertion marker in this event handler. Otherwise, you can use the standard caret. In latter case, just call the RichEditControl.Focus() method in the control's DragEnter event handler. Finally, note how the RichEditControl.ScrollToCaret Method is used to scroll the document to the caret position if you move the caret outside of the visible document area.

Question Comments

Added By: Sandesh Prabhudesai 1 at: 12/8/2015 12:43:09 PM    

I used the vb code you have listed below to drag rtffile/rtftext . However, when it enters the DragDrop event, if I check the richEditControl1.RtfText, it shows that the text I am dragging is already pasted in it.

This causes it to paste the text twice. The method InsertRtfText I am calling puts the text correctly, But the text  added by the event automatically has rtftext in it.

For example Here is the text added by default
{\rtf1\ansi\ansicpg1252\deff0\deflang1033{\fonttbl{\f0\fnil\fcharset0 Microsoft Sans Serif;}}
\viewkind4\uc1\pard\f0\fs17 We appreciate your business!\par
}

Here is the text added by my InsertRtfText method call

                We appreciate your business!

Please help.
Sandesh

How to: Create Information Panels

$
0
0

In certain scenarios you may be required to create additional functional regions in a UI to display specific data. This task can be solved by including additional controls into XAF templates and implementing the code that will supply data to the controls. To help you with the task, XAF offers built-in CustomizeTemplateViewControllerBaseController and complete design-time support for built-in templates. Combined, these features allow you to easily implement information panels that can display Actions, Views and any kind of data accessible from a View Controller. This topic describes the steps you need to perform to create a simple information panel. For general information on template customization, refer to the Template Customization help topic.


Include Required Templates into the Application

First, you need to decide which Templates you will customize. Different Templates are used in different parts of an application. To see a complete list of built-in Templates along with their descriptions, refer to the Templates topic. In this example, Windows Forms MainForm and DetailViewForm Templates will be customized as well as the ASP.NET DefaultVertical Template.


- Windows Forms Templates

Built-in Windows Forms Templates are regular classes located in the DevExpress.ExpressApp.Win assembly. To customize them, you need to include corresponding source code files into your solution and handle the XafApplication.CreateCustomTemplateevent. To learn how to do this, refer to the How to: Customize a Windows Forms Template help topic.

- ASP.NET Templates

Built-in ASP.NET Templates are pages whose content is taken from User Controls located in the DevExpress.ExpressApp.Web assembly. To customize them, you need to include corresponding source code files into your solution and modify the appropriate setting exposed via the WebApplication.Settings property. To learn how to do this, refer to the How to: Customize an ASP.NET Template help topic.

After all the required Templates are included in your solution, you can begin adding panel controls to them.


Add Panel Controls to Windows Forms Templates

To add a panel control to the MainForm or the DetailViewForm Template, right-click the Template in the Solution Explorer and choose "View Designer".


Locate the viewSitePanel control and change its Dock property from Fill to None.

To ensure that the Template can be correctly resized, set the SplitContainerControl’s Dock property to Fill and the FixedPanel property to Panel2.

To be able to fill the information panel with data, the SplitContainerControl must be externally visible. For this purpose, define an interface via which the information panel will be accessed. This will decouple data-supplying Controllers from particular Template types. Instead they will rely on the interface.

[C#]
publicinterfaceIInfoPanelTemplateWin:IFrameTemplate{DevExpress.XtraEditors.SplitContainerControlSplitContainer{get;}}

Then, implement the interface in the Templates.

[C#]
publicpartialclassMainForm:MainFormTemplateBase,IDockManagerHolder,ISupportClassicToRibbonTransform,IInfoPanelTemplateWin{//... publicDevExpress.XtraEditors.SplitContainerControlSplitContainer{get{returnsplitContainerControl1;}}}

Add Panel Controls to ASP.NET Web Templates

To add a panel control to the DefaultVertical Template, right-click the ASCX file that you have added as a replacement for the standard DefaultVertical content and choose "View Markup".

Add the following two cells to the MRC table.

[ASPx]
<tdid="RS"style="width: 6px; border-bottom-style: none; border-top-style: none"class="dxsplVSeparator_<%= BaseXafPage.CurrentTheme %> dxsplPane_<%= BaseXafPage.CurrentTheme %>"><divid="RSB"class="dxsplVSeparatorButton_<%= BaseXafPage.CurrentTheme %>"onmouseover="OnMouseEnter('RSB')"onmouseout="OnMouseLeave('RSB')"onclick="OnClick('Right', 'RSI')"><divid="RSI"style="width: 6px;"class="dxWeb_splVCollapseForwardButton_<%= BaseXafPage.CurrentTheme %>"/></div></td><tdid="Right"width="250px"style="vertical-align: top"><cc3:XafUpdatePanelID="UPRight"runat="server"/></td>

The UPRight control in this markup will represent the information panel.

Open the code-behind file of your ASCX - right click the file and choose View Code.


Expose the protected UPRight control via the public property.

[C#]
publicpartialclassMyDefaultVerticalTemplateContent:TemplateContent{publicControlPlaceHolder{get{returnUPRight;}}// ... }

In the ASP.NET module project, define an interface via which the information panel will be accessed from controllers.

[C#]
publicinterfaceIInfoPanelTemplateWeb:IFrameTemplate{ControlPlaceHolder{get;}}

Implement this interface in the Default template - edit the Default.aspx.cs file located in the ASP.NET application project.

[C#]
publicpartialclassDefault:BaseXafPage,IInfoPanelTemplateWeb{publicControlPlaceHolder{get{returnTemplateContentisMyDefaultVerticalTemplateContent?((MyDefaultVerticalTemplateContent)TemplateContent).PlaceHolder:null;}}// ... }

Now you need to implement Windows Forms and ASP.NET Web View Controllers that will supply panel controls with actual data. To simplify this task, XAF provides the CustomizeTemplateViewControllerBase<TemplateType> Controller to inherit from. For convenience, the TemplateType generic parameter can be either a template type or an interface implemented by templates. CustomizeTemplateViewControllerBase already provides template access logic, so all that you should do is implement four protected abstract methods.


- AddControlsToTemplateCore(TemplateType template) - called when a Controller is activated. This method must instantiate required controls and add them to an information panel.

- RemoveControlsFromTemplateCore(TemplateType template) - called when a Controller is deactivated. This method must remove previously added controls from the information panel.

- UpdateControls(View view) - called when the current View is changed. This method must update information panel controls with View-specific information, if required.

- UpdateControls(object currentObject) - called when a currently displayed object is changed. This method must update information panel controls with data specific to the currently displayed object, if required.

The implementations of WinForms and ASP.NET controllers are demonstrated in the InfoPanelViewControllerWin.cs and InfoPanelViewControllerWeb.cs files of this example.

Note: Alternatively, you can access the XAF template and customize it to implement a standard ASP.NET technique for your task (for example, Serving Dynamic Content with HTTP Handlers).

Question Comments

Added By: Willem de Vries at: 12/17/2012 10:36:33 PM    

I'd like to see how the current skin can be applied to the panel.

Added By: Konstantin B (DevExpress) at: 12/21/2012 3:10:33 AM    

Hi Willem. You can see it in the FeatureCenter demo ("Frame Templates" | "Info Panels" section).

Added By: MohammedFarooq at: 12/8/2015 11:07:44 PM    

When i implemented this is in my main project, i am getting the following error. Eventhough the definition of Placeholder is properly available in files.

Error 12 Class 'Default' must implement 'ReadOnly Property PlaceHolder As System.Web.UI.Control' for interface 'MyProject.Module.Web.IInfoPanelTemplateWeb'. Implementing property must have matching 'ReadOnly' or 'WriteOnly' specifiers. G:\MyProject.Web\Default.aspx.vb

How to use ASPxDataView with ASPxFormLayout to show records one by one

$
0
0

To implement such a functionality, you first need to set up the ASPxDataView so that it shows only one record at a time. To do so, set the Rows and Columns count to 1. Then place ASPxFormLayout into ItemTemplate and handle its DataBinding event to bind it to the ASPxDataView's DataItem. To update edited records, place the ASPxButton under the ASPxFormLayout. On its click, iterate through UpdateParameters of the SqlDataSource and set its values to those from the ASPxFormLayout.

Question Comments

Added By: Dhaval.Shah at: 12/8/2015 7:00:18 PM    

An alternate way to achieve the same could be:

1. Have each item in the ASPxFormLayout bound to data.
Example:
<dx:LayoutItem Caption="Title" FieldName="Title">
...
2. Declare the Dataview's PageIndexChanged event in which we will assign the datasource to the form layout control (globally)
Example:
       protected void DataView_PageIndexChanged(object sender, EventArgs e)
       {
           ASPxFormLayout flView = LoadcaseDataView.FindItemControl("ASPxFormLayout1", DataView.VisibleItems[0]) as ASPxFormLayout;
           flView.DataSource = DataView.VisibleItems[0].DataItem;
           flView.DataBind();
       }

This will achieve the same functionality I believe. Note that there is only 1 record per "view" (1 column, 1 row) which makes this work, as there is only one "VisibleItem" of the dataview per page.
So, when the page index has changed, the VisibleItems[0].DataItem reflects the current record correctly.

This is just for navigation and rest of the functionality mentioned here is still valid.
I do stand to be corrected however.

Added By: Jenny (DevExpress Support) at: 12/8/2015 11:22:20 PM    

Hello,

In this example, you do not need to handle the PageIndexChanged event. When an active page is changed, the ASPxFormLayout1_DataBinding event is raised. So, you just need to correctly specify ASPxFormLayout's data source.

How to edit multiple property values in a single PropertyGridControl cell

$
0
0

This example demonstrates how to show multiple editors within one cell by overriding the ContentTemplate.
The recommended approach is to put CellEditorPresenter to ContextTemplate and set its Path property to the name of the required property:

[XAML]
<dxprg:PropertyDefinition.ContentTemplate><DataTemplate><StackPanel><dxprg:CellEditorPresenterPath="x"PathMode="Absolute"/><dxprg:CellEditorPresenterPath="y"PathMode="Absolute"/><dxprg:CellEditorPresenterPath="z"PathMode="Absolute"/></StackPanel></DataTemplate></dxprg:PropertyDefinition.ContentTemplate>

The native navigation, inplace editing, and other similar features will work automatically in this case.

How to integrate the Web Report Designer into an MVC web application

$
0
0
This example demonstrates how you can integrate the Web Report Designer into your web application. The application contains a simple report catalog, allowing you to add, delete, and edit reports whose layout data is stored in a custom data storage (i.e., an MS SQL database).

 

Additionally, this example demonstrates how you can add custom commands to the report designer menu at runtime to provide better integration with your application. In the example, the custom Save&Close menu command is introduced, which redirects you to the catalog page after saving the report.

 
Important note: Starting with version 15.2, the ReportStorageWebExtension is used to manage the reports storage for the Web Report Designer instead of the controller actions. 

Question Comments

Added By: bcoffee at: 4/6/2015 9:50:04 AM    

I'm trying to use this example to run a save report in DocumentViewer but I'm having no luck. Is it possible to extend this example to Run function in addition to Create, Edit and Delete?

Added By: Yaroslav (DevExpress Support) at: 4/6/2015 11:59:18 AM     To avoid discussing multiple topics in this thread, I've extracted your question to the How to run a save report in DocumentViewer ticket created on your behalf. Let's continue our conversation there.

How to: Use services implementing the IDocumentManagerService interface


How to: Set a property to a custom value via the Popup Menu

$
0
0
This example shows how to use InstanceInitializerAttribute to create objects of a class that does not contain the default constructor (without the parameters).

Click the New Client button within the Clients property menu to set a Client class instance as the property's value.

How to: Generate properties in PropertyGridControl from a collection

$
0
0
To generate properties from a collection, assign the collection to the PropertyDefinitionsSource property. To determine what property definitions will be generated, use the PropertyDefinitionTemplate property. If the collection contains PropertyDefinitions, it's not necessary to use PropertyDefinitionTemplate.

How to: How to customize the way properties are displayed/edited in XAML

$
0
0

This example demonstrates how to customize displayed properties in XAML by adding the required Property Definitions and Collection Definitions objects to the PropertyGridControl.

There are several properties you can use to map PropertyDefinition objects to properties:

Path - the path to the property;

Scope - the path to the parent property;

Type - the type of the property.

To learn more on this functionality, refer to Property Definitions.

 

Note that we have set the PropertyGridControl.ShowProperties property to ‘WithPropertyDefinitions’ to show only properties for defined definitions. You can remove this setter to be able to see all object properties.

How to: Configure the way properties are displayed/edited at the data model level

$
0
0

The DXPropertyGrid supports a large number of attributes from the System.ComponentModel.DataAnnotations library as well DevExpress attributes (see Data Annotation Attributes for more information), and you can use them to control the way properties are displayed.

In this example, we used several attributes including the PropertyGridEditorAttribute, which allows you to specify a particular editor for a property in the PropertyGridControl.

How to Access the Document Manager

ASPxGridView - How to implement Excel-like comment functionality for cells

$
0
0

This example illustrates how to provide an end-user with the capability to assign comments to different cells (this is similar to the Excel-based feature: Annotate a worksheet by using comments). Here are implementation details:


All comments as stored in the dictionary:
[C#]
publicstaticclassCommentsStorage{privatestaticDictionary<Tuple<object,string>,string>Comments...

The first parameter (Tuple) is a compound key value that consists of a row key and column name. The second parameter is a comment text. Although in the current implementation all values are stored in the Session variable, you can easily modify the CommentsStorage class method to store them in the database if necessary.

As for the ASPxGridView-specific implementation part, we handle the ASPxGridView.HtmlDataCellPrepared event to assign the required attributes, CSS styles and client-side event handlers (onmouseover, oncontextmenu) to cells. We customize the Context Menu for rows to display the Insert/Edit/Delete commands for end-users, so that they can modify comments at runtime. Finally, we use two ASPxPopupControl instances to display and edit comments correspondingly.

GridView - How to filter Chart data based on the grid filter

$
0
0

This example illustrates how to display only those data rows in the Chart extension, which are displayed in the GridView extension according to its current filter state (e.g., see Filter Row - ASP.NET MVC Extensions - Grid View Demo). Unlike the approach illustrated in the T177863 - ASPxGridView - How to make WebChartControl display only data that is visible in grid code example (for the WebForms platform), we use filtering at the database level to display data in a Chart. Note that the sorting order is not retained in this scenario, but the performance is much better for large data sources. The key idea here is to use the CriteriaToWhereClauseHelper class method to convert the ASPxGridView.FilterExpression property value to the database-specific filter query. Please review the K18434 - How to convert the CriteriaOperator to the corresponding filter string in order to use it for building SQL queries or for filtering the DataView and A2921 - How to get a list of the data rows in a filtered grid KB articles to learn more on this subject.


Getting Started with the Scheduler

How to: Add an object with predefined property values using the Collection Editor

$
0
0

The DXPropertyGrid supports adding new objects to collections using the collection editor. To pre-set certain properties for a new object or create an object without the default constructor, use the CollectionDefinition.NewItemInitializer property. Like PropertyDefinitionBase.InstanceInitializer, it should be set to an object that implements the DevExpress.Mvvm.Native.IInstanceInitializer interface.

Question Comments

Added By: Andrew Roberts 5 at: 11/5/2014 3:02:37 PM    

I am trying to use this example but the ItemInitializer class needs to be in a ViewModel and the dxprg:CollectionDefinition is part of a DataTemplate in a separate file. I can't use NewItemInitializer as suggested in this sample.

Tried:
NewItemInitializer="{Binding RelativeSource={RelativeSource Mode=FindAncestor, AncestorType=UserControl}, Path=DataContext.ItemInitializer}"

Received error:
System.Windows.Data Error: 40 : BindingExpression path error: 'ItemInitializer' property not found on 'object' ''WorkstationsEditorViewModel' (HashCode=43595579)'. BindingExpression:Path=DataContext.ItemInitializer; DataItem='WorkstationsEditorView' (Name='workstationsEditorView'); target element is 'CollectionDefinition' (Name=''); target property is 'NewItemInitializer' (type 'IInstanceInitializer')

So it’s looking for a property on WorkstationsEditorViewModel

So I did this on the ViewModel:

public ItemInitializer ItemInitializer {
           get { return new ItemInitializer();}

Now not throwing errors, but I'm not getting the Collection property showing in the Property Grid

Added By: Andrey Marten (DevExpress Support) at: 11/5/2014 11:41:05 PM    


Hello,

To process your recent post more efficiently, I created a separate ticket on your behalf: T169706: Example E4855 - Moving ItemInitialized to the View Model raises a binding exception. This ticket is currently in our processing queue. Our team will address it as soon as we have any updates.

Thanks,
Andrey

How to: Convert a value entered by a user to a custom type

$
0
0
Let’s assume that you have a property of a custom type and want to edit it in the PropertyGridControl. To be able to convert a value entered by a user (for example, this may be a string value) to the custom type, use a TypeConverter class descendant. It can be applied using the TypeConverterAttribute attribute:
[C#]
[TypeConverter(typeof(MyTypeConverter))]publicCustomerValue{   get;   set;}

How to create a DXRibbonWindow

How to create a RibbonControl

$
0
0

This example shows how to create RibbonControl in XAML.

Below are links to documentation articles describing how specific parts of this example were implemented:
- How to create a RibbonControl;
- How to define a default ribbon category with commands;
- How to define a custom ribbon category;
- How to create an Application Menu;
- How to: Add Items to the Quick Access Toolbar;
- How to: Add Commands to the Page Header Region;
- How to create a BarButtonGroup;
- How to define an in-ribbon gallery;
- How to define a RibbonStatusBar.

Question Comments

Added By: James Doran at: 9/7/2014 6:55:52 PM    

The "example" download file has a dxsample extension which should be "zip"

Added By: Michael Ch (DevExpress Support) at: 9/7/2014 11:37:38 PM    

Hello,

To process your recent post more efficiently, I created a separate ticket on your behalf: T148241: Example file extension. This ticket is currently in our processing queue. Our team will address it as soon as we have any updates.

Viewing all 7205 articles
Browse latest View live


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