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

How to use an unbound check box column to select grid rows

$
0
0

From version 13.2, the GridView in the XtraGrid control provides a built-in checkbox column for multiple row selection.
This feature is demonstrated in the example that targets version 13.2. Additional information can be found in the following topic: Multiple Row Selection via Built-In Check Column

If you are using an earlier version of DevExpress controls, see the attached example that targets this earlier version.
This example demonstrates a method to manually create a check column for row selection. The example is similar to the one from the A371 article. The difference is that this example employs the grid's built-in multi-selection and keeps it in sync with the check boxes. All code related to selection is placed into the GridCheckMarksSelection helper class, so it should be easy to port this functionality to your application.
Please note if you use the AppearanceEvenRow and AppearanceOddRow styles, by default they have a higher priority than the RowStyle event used for the selection in this example. To avoid drawing incorrect selected rows, enable the e.HighPriority option. See Also: E1271

Question Comments

Added By: Marco Villasesr at: 2/2/2014 8:31:14 AM    

Could you please attach a sample Project, please? thank you!!

Added By: david ola at: 12/17/2015 5:18:30 AM    

How do you respond to the selection change event? I needed to populate another grid based on the number of rows selected in my gridcontrol. Everything works well until no rows were selected. At that time, the SelectionChange event did not work. The other grid should be cleared when selectionCount become zero in my original gridcontrol, but it still displays the contents as if SelectionCount =1.
Is that a bug?

Added By: Nadezhda (DevExpress Support) at: 12/17/2015 12:43:08 PM    

Hello,

Before I suggest a solution, I need to know which approach you use. Do you utilize the GridCheckMarksSelection helper class or the CheckBoxRowSelect select mode?

I look forward to hearing from you.


How to calculate a weighted average function

$
0
0

This example demonstrates how to calculate a weighted average function. To do this, create a calculated field and in its expression, refer to two data fields and separate them using a special sign (such as "|").

Then, create a summary label bound to this calculated field with a custom summary function defined. Handle the label's SummaryGetResult event to parse the calculated field's value and calculate a weighted average function.

Question Comments

Added By: Abdul Shareef1 at: 3/12/2013 3:13:38 PM    

Can you please explain me how to do the following step for two numeric fields?

To do this, create a calculated field and in its expression, refer to two data fields and separate them using a special sign (such as "|").

Added By: George (DevExpress) at: 3/14/2013 5:50:49 AM    

Please open this project in Visual Studio, and in the Field List panel, right-click the "fieldWeight" calculated field. In the invoked popup menu, select "Edit Expression...", which runs the field Expression editor. In this editor, you can view the following expression: ToStr([UnitPrice] * [UnitsInStock]) + '|' + ToStr([UnitPrice])

Added By: Farukh Sharipov at: 6/14/2013 4:09:28 PM    

Can you explain more how to do two numeric fields? Maybe attach screencast?

How to bind GridView with standard in-memory data sources (DataTable, List)

$
0
0

This example illustrate how to bind the MVC GridView Extension with the standard in-memory data sources:

- The ADO.NET DataTable - DataTableDataBinding View / DataTableDataBindingPartial Partial View;

- The Typed List (List<T>) - TypedListDataBinding View / TypedListDataBindingPartial Partial View.


The GridView's definition contains:

- Set of Data Columns whose values are retrieved from the underlying datasource (the /*Data-Bound Columns*/ section);

- A single Unbound Column (the /*Unbound Columns*/ section) whose values are computed based on the bound columns' values (the /*Unbound Column Calculating*/ section).


Both data sources (Models) have the same set of fields. These Models are defined within the /Models/Model code file.

See Also:
E3983: GridView - How to edit in memory data source
E3998: GridView - How to specify a custom EditForm Template

Question Comments

Added By: Lori Post at: 1/22/2013 7:43:28 AM    

How would this be done with an IQueryable datasource? I'm using the BindToLinq method to deal with large amounts of data. I need an in memory collection since I will be modifying items in an in memory collection based on updates to the list, and at the very end there will be a second page which will be a confirmation showing the changes in the grid and whether the user would like to continue with the changes.

Report Storage for the End-User Report Designer

$
0
0

The following example demonstrates how to implement a report storage to persist report definitions in a database or in any other custom location. This may be useful when providing end-users with the capability to create and customize reports using XtraReports End-User Designer, if it is necessary to have a common target for saving and sharing all reports.

The default report serialization mechanism does not support the serialization of a report's data source. The following examples illustrate how you can provide a custom XML serialization logic for a report's data source as well as its custom parameters.

- How to implement custom XML serialization of a report that is bound to a dataset;

- How to serialize an XPO data source;

- How to serialize parameters of custom types.

Question Comments

Added By: (no info) at: 10/8/2012 10:48:21 AM    

There is a slight error in the example if you are using a different XPO provider. The call to create the XpoReportStorage is prior to setting the default DataLayer. This results in the default MS Access DataLayer being used in the XpoReportStorage parameter. Changing the statement (as indicated below) will result in the expected behavior:

string conn = SQLiteConnectionProvider.GetConnectionString(@"c:\temp\ReportStorage.sqlite");
XpoDefault.DataLayer = XpoDefault.GetDataLayer(conn, AutoCreateOption.DatabaseAndSchema);
reportStorage = new XpoReportStorage(new UnitOfWork());

Added By: Patrick Sollberger at: 7/6/2013 2:03:23 AM    

A hint for all those wo tried this with version 13.1.4:

This Example can not be built as-is using DevExpress 13.1.4 even after project conversion.

The ZipReportStorage.cs contains renamed classes:
- ZipFileCollection is now named InternalZipFileCollection
- ZipFile is now named InternalZipFile
- ZipArchive is now named InternalZipArchive

After renaming all occurences of those classes with the new names everything works just fine.

Added By: BINITR at: 10/25/2013 2:18:39 PM    

I'm trying to connect to the datasource Sqlite but I can not figure out how to do. I also downloaded the componeti OleDb for Sqlite but without result.

Added By: Wim Koppelaar at: 5/24/2015 2:59:21 AM    

Nice example of the possibillities. But I don't understand where StorageDataSet is comming from?

Added By: Vasily (DevExpress Support) at: 5/25/2015 5:56:39 AM    Hi Wim,

StorageDataSet is a regular DataSet class created by using the Visual Studio DataSet designer. Note that not all project files are usually displayed in the file selection combo box of the code example. So, if you have any questions regarding the example implementation, it is better to download the whole code example project and review its source code in the Visual Studio IDE. Please refer to the following ticket for more information: How to download code examples.

Added By: Yohan Dole 1 at: 12/17/2015 7:22:53 PM    

I tried to change the DataSet to a MS-SQL Table....but keep getting a "Cannot implicitly convert type 'ReportStorageSample.DataSet1.reportsRow' to 'ReportStorageSample.StorageDataSet.ReportStorageRow' " .. This is caused by the field "Buffer" which is varbinary on the DB side.

Added By: Jannet (DevExpress Support) at: 12/17/2015 10:37:11 PM    Hello Yohan,
To handle your inquiry in the most efficient manner, let's continue our discussion at Report & Sub Report stored in a Database Table.

How to create a custom Edit Appointment form using the MVVM pattern

$
0
0
This example demonstrates how to substitute the standard Edit Appointment form with the custom one using the MVVM approach. The new technique is based on a service provided by a data template. This service allows displaying a form in a separate window. 

See also: 
How to: Create a Custom Edit Appointment Form Using the MVVM Pattern (step-by-step guide)

Question Comments

Added By: Cliff Knasinski at: 8/27/2014 9:05:27 AM    

I have an issue with using this example to commit the changes to my custom field back to the MS SQL Server database.  I am utilizing a design structure that is not represented in the examples from DevExpress.  I am using a LINQ to SQL class as my data model, and View Models to bind to those models.

Since I am unable to use the LINQ .CommitChanges method from the custom appointment form since I cannot send it as a parameter to the constructor using this example.  My View Model reflects the changes made by the form since it is bound two ways, but I have no way to fire off the .CommitChanges method.  

I noticed there is a ..

<Button x:Name="btnOk"
               Content="OK"
               Command="{Binding SaveAppointmentCommand}" MinWidth="75" Margin="6,0,0,0"/>

But this command is not used in the example.  I have not delved into commands yet, is there an example I can use that would allow me to fire off a method in the View Model this is bound too in order to commit changes to the database?

Added By: Oleg (DevExpress Support) at: 8/28/2014 1:24:06 AM    

Hello Cliff,
To process your recent post more efficiently, I created a separate ticket on your behalf: T144939: How to manually create/modify source objects in the underlying data source when a custom Appointment Form is used. This ticket is currently in our processing queue. Our team will address it as soon as we have any updates.

How to save and restore settings of all controls that are present in the UI

How to print the ASPxScheduler using a Report Preview

How to save and restore the DockLayoutManager layout

$
0
0

DockLayoutManager provides several methods to save and restore layout settings:
- SaveLayoutToStream;
- SaveLayoutToXml;
- RestoreLayoutFromStream;
- RestoreLayoutFromXml.

Note that item names are used to identify them when saving/restoring a layout, so it will be necessary to set names for all DXDocking items to make sure that settings will be restored properly.

It may happen that some panels were added/removed after the DockLayoutManager's layout was saved. In this scenario, DockLayoutManager will remove panels that are not present in the saved layout and ignore saved settings for items that do not exist anymore. To change this behavior, set the following options:
- To re-create panels that are present in the saved layout, set RestoreLayoutOptions.RemoveOldPanels to False.
- Set RestoreLayoutOptions.AddNewPanels to True to maintain panels that are not present in the saved layout.

Please note that the DockLayoutManager's methods save settings only of its groups and panels. To save settings of embedded controls, use WorkspaceManager as shown at How to save and restore settings of all controls that are present in the UI.

See also:
How to serialize a particular panel layout
How to serialize custom panels and their properties
How to save and restore settings of all controls that are present in the UI


How to create items with subitems in TileBar using XAML

$
0
0

This example shows how to populate TileBar in XAML. To add an item into TileBar, add the TileBarItem element into the TileBar.Items collection. Please note that Items is a content property, so you can skip its tag when using it in XAML. To show an image in TileBarItem, use the TileGlyph property. 

How to: use the AppBar control to create a menu that is shown on top or bottom of the window

$
0
0

This example shows how to create an app bar containing custom regular and toggle buttons, the predefined Exit button, and the button that displays a flyout when clicked.

In this example, the AppBar control is populated with the AppBarButton and AppBarToggleButton objects, which are divided into groups using the AppBarSeparator objects. To display the predefined Exit button, the IsExitButtonEnabled property is set to True.

The button captions are specified using the AppBarButton.Label property. The HorizontalAlignment property specifies the button alignment relative to the app bar.

The CommandButton.Glyph property is used to provide the buttons with icons from the DX Image Gallery. The glyph theming feature is enabled for all buttons and the glyph height is set using the Style declared in the app bar's Resources. You can also use the button's Content property to specify the button icons. See the Pin button — the icon for this button is specified using the Unicode symbol that corresponds to the glyph in the Segoe UI Symbol font. For more information about how to use Segoe UI Symbol icons, see Guidelines on MSDN.

The Rotate button displays the flyout when clicked. The button's Flyout property allows you associate the Flyout or MenuFlyout control with the button.

 How to: create TileNavPane navigation buttons and categories in XAML

$
0
0

This example shows how to create a TileNavPane, populate it with navigation elements and add custom buttons to the nav bar.

In the XAML markup, four buttons are added to the NavButtons collection. Buttons added to this collection are displayed in the nav bar. The first, which is aligned at the left margin of the nav bar, is the Main Button. The IsMain property of this button is set to true. Other buttons are aligned to the right using the HorizontalAlignment property. The second button contains items, and so a drop-down tile bar is invoked when this button is clicked. Button glyphs are differently aligned (theGlyphAlignment property) and the rightmost button does not have a textual content (the Content property). All glyphs are specified to be displayed with the glyph theming feature enabled (the AllowGlyphTheming property).

One category (TileNavCategory) is added the Categories collection. This category contains one child item, which in turn contains two sub-items. The textual and graphical content of tiles is specified with the TileContent and TileGlyph properties. Textual content of the corresponding buttons in the nav bar is specified with the Content property.

How to: navigate from one view to another in the NavigationFrame when navigation logic is implemented at the view level

$
0
0

This example demonstrates how to navigate between views without executing code at the view model level. If you wish to control navigation from the view mode, please refer to: How to: Navigate between Views via FrameNavigationService.

In this example, the NavigationButton element is used to perform navigation. To specify the target view, use the NavigateTo property. If you wish to use the standard Button, set the dxwuin:Navigation.NavigateTo attached property:

[XAML]
<ButtonContent="Tools"dxwuin:Navigation.NavigateTo="ToolsView"/>

Please note that the approach with the NavigationButton and Navigation.NavigateTo properties works only if the button is located in the NavigationFrame's visual tree.  You can also use the NavigationFrame.Navigate method to initiate navigation from code-behind. To specify the start view, set the Source property.


In this example, each view contains the PageAdornerControl. This element consists of a header and a back button. As a rule, the header is used for navigation buttons and for displaying the view name. The back button is visible only when the ShowBackButton is true.

To cache views in order to improve performance, set the NavigationCacheMode to "Required".

OBSOLETE - How to populate ComboBoxEdit with enumeration elements

$
0
0

======================
This article is now obsolete starting from 14.2. Refer to the How to: Use EnumItemsSourceBehavior ticket instead.
======================

To bind ComboBoxEdit to an enum, use the EnumItemsSource markup extention in the following manner:

[XAML]
<dxe:ComboBoxEditItemsSource="{dxe:EnumItemsSource EnumType=local:MyEnum}"/>

For version 13.1 and earlier:
All logic is encapsulated in the BaseComboBoxStyleSettings descendant which is defined in the MyComboBoxStyleSettings.cs(vb) file. The representation of items in the popup window depends on the enumeration items kind. E.g., if enumeration items have description attributes they will display the description text instead of item names. If the enumeration definition is decorated with the FlagsAttribute attribute, items will be represented as check editors with the TextBlock element used as description.

Question Comments

Added By: Marcin Sulecki at: 11/13/2014 5:33:39 AM    

I has just Description attribute to MyEnum but ComboBoxEdit displays item names instead description. I use version 14.1

public enum MyEnum
   {
       [Description("Eating")]
       Eat,

       [Description("Sleeping")]
       Sleep,

       [Description("Coding")]
       Code
   }

I count on your help.

Added By: Ilya (DevExpress Support) at: 11/13/2014 6:52:34 AM    

Hello,

To process your recent post more efficiently, I created a separate ticket on your behalf: T173028: How to display description of an enum item when EnumItemsSource is used in ComboBoxEdit. This ticket is currently in our processing queue. Our team will address it as soon as we have any updates.

Added By: Matthias Adloff at: 12/19/2015 1:25:17 PM    

I suggest you should not mark this as obsolete. If just a simple enum binding is needed, it's probably easier and quicker to implement it like shown here. Furthermore the EnumItemsBehavior is not working for a ComboBox embedded into a GridControl, right? Thus, the solution shown here is even less obsolete. I'd love to stand corrected.

How to: implement selection in the MVVM style

$
0
0
This example demonstrates how to implement chart element selection in the MVVM style.

GridView - How to update total summaries on the client side in Batch Edit mode

$
0
0
This example demonstrates how to update total summaries on the client side when GridView is in Batch Edit mode. To implement the required task, perform the following steps:

1. Add a total summary item for a required column. The Tag property is used to find this summary item and get its value: 

[C#]
settings.Columns.Add(column=>{column.FieldName="C2";column.ColumnType=MVCxGridViewColumnType.SpinEdit;ASPxSummaryItemsummaryItem=newASPxSummaryItem(column.FieldName,DevExpress.Data.SummaryItemType.Sum);summaryItem.Tag=column.FieldName+"_Sum";summaryItem.DisplayFormat="{0}";settings.TotalSummary.Add(summaryItem);});

 2. Replace the summary item with a custom Footer template:

[C#]
column.SetFooterTemplateContent(c=>{Html.DevExpress().Label(lbSettings=>{stringfieldName=(c.ColumnasGridViewDataColumn).FieldName;lbSettings.Name="labelSum";lbSettings.Properties.EnableClientSideAPI=true;ASPxSummaryItemsummaryItem1=c.Grid.TotalSummary.First(i=>i.Tag==(fieldName+"_Sum"));lbSettings.Text=c.Grid.GetTotalSummaryValue(summaryItem1).ToString();}).Render();});


 3. Handle the grid's client-side BatchEditEndEditing event to calculate a new summary value and set it when any cell value has been changed:

[JScript]
function OnBatchEditEndEditing(s, e){var originalValue = s.batchEditApi.GetCellValue(e.visibleIndex, "C2");var newValue = e.rowValues[(s.GetColumnByField("C2").index)].value;var dif = newValue - originalValue; labelSum.SetValue((parseFloat(labelSum.GetValue()) + dif).toFixed(1));}

4. Finally, replace standard Save changes and Cancel changes buttons with custom buttons to refresh a summary value when all modifications have been canceled:

[C#]
settings.SetStatusBarTemplateContent(c=>{ViewContext.Writer.Write("<div style='text-align: right'>");Html.DevExpress().HyperLink(hlSettings=>{hlSettings.Name="hlSave";hlSettings.Properties.Text="Save changes";hlSettings.Properties.ClientSideEvents.Click="function(s, e){ GridView.UpdateEdit(); }";}).Render();ViewContext.Writer.Write(" ");Html.DevExpress().HyperLink(hlSettings=>{hlSettings.Name="hlCancel";hlSettings.Properties.Text="Cancel changes";hlSettings.Properties.ClientSideEvents.Click="function(s, e){ GridView.CancelEdit(); GridView.Refresh(); }";}).Render();ViewContext.Writer.Write("</div>");});


See Also:
GridView - Batch Edit - How to calculate values on the fly 
GridView - Batch Edit - How to calculate unbound column and total summary values on the fly

ASP.NET Web Forms Example:
ASPxGridView - How to update total summaries on the client side in Batch Edit mode 

Question Comments

Added By: Rabab Siblini at: 12/20/2015 10:45:32 PM    

Perfect


How to serialize DockLayoutManager when TabbedDocumentUIService is used

$
0
0

Some of DockLayoutManager’s panel groups can contain documents that were created from ViewModel with IDocumentManagerService. To serialize and restore them correctly, it is necessary to perform the following steps.

Item names are used to identify items when saving/restoring the layout. For this reason, it will be necessary to set unique names for all DockLayoutManager panels. In the current scenario, this can be done by setting the DocumentPanel.BindableName property in the TabbedDocumentUIService.DocumentPanelStyle.

Another important point is that the DockLayoutManager's saving/restoring mechanism is not the XamlWriter alternative - it does not save/restore content of its panels. It will be necessary to additionally restore it. In this example, we used the following approach:
1. Before saving layout settings, serialize all documents created from the ViewModel.
2. Before restoring settings, recreate all documents.

How to: Arrange items horizontally and vertically

$
0
0
To arrange DockLayoutManger items horizontally or vertically, use Layout Group objects. A LayoutGroup is a container that may contain different items:

- Other Layout Groups;
- Layout Panels;
- Tabbed Groups;
- Document Groups;
- Layout Control Items.

A layout group can arrange its items either horizontally or vertically. The orientation can be changed by setting the LayoutGroup.Orientation property.

In this example, we demonstrated how to build a layout with items arranged vertically and horizontally.

For this, we used a combination of vertical and horizontal layout groups.

How to display items in tabs

$
0
0

The DXDocking suite provides several approaches to display content in tabs. For this, you can use either of the following containers

- A LayoutGroup with GroupBorderStyle set to Tabbed;
- A TabbedGroup;
- A DocumentGroup.

In this example, we demonstrated all three approaches.


Although all these groups allow displaying tabs, they are designed for use in different scenarios.
A DocumentGroup will be the best choice if the task is to display dynamic content. It works similar to the document area in the Visual Studio.

A TabbedGroup is designed to display more static content like toolbars, service information, etc.

A LayoutGroup with the Tabbed style is intended to display a static set of elements. Unlike DocumentGroup and TabbedGroup, it supports moving tabs only in customization mode.

How to build a layout similar to Visual Studio

$
0
0

Let’s see how to build a layout similar to Visual Studio using the DXDocking Suite. Below is the screenshot of the Dock Windows -> VS2010 Docking demo.

The window layout contains the following elements:


The Solution Explorer panel.


To display such a panel, use a single Layout Panel item.

[XAML]
<dxdo:LayoutPanelCaption="Solution Explorer"/>

Several panels are displayed as tabs at the bottom.


There are several ways to display tabs in DXDocking. Please refer to How to display items in tabs to be aware of all available options. In this scenario, use a Tabbed Group, as it supports reordering panels, removing and adding new panels.

[XAML]
<dxdo:TabbedGroup><dxdo:LayoutPanelCaption="Error List"/><dxdo:LayoutPanelCaption="Output"/><dxdo:LayoutPanelCaption="Breakpoints"/></dxdo:TabbedGroup>

The document area.

While the Tabbed Group is intended to display static panels like toolbars, background information, etc., Document Groups can be used to display dynamic content (like opened documents) and provides the functionality similar to Visual Studio’s document area.

[XAML]
<dxdo:DocumentGroup><dxdo:DocumentPanelCaption="MainWindow.xaml"/><dxdo:DocumentPanelCaption="MainWindow.xaml.cs"/></dxdo:DocumentGroup>

To arrange these elements, use a combination of vertical and horizontal Layout Groups.

[XAML]
<dxdo:LayoutGroupOrientation="Horizontal"><dxdo:LayoutGroupOrientation="Vertical"><dxdo:DocumentGroup><dxdo:DocumentPanelCaption="MainWindow.xaml"/><dxdo:DocumentPanelCaption="MainWindow.xaml.cs"/></dxdo:DocumentGroup><dxdo:TabbedGroup><dxdo:LayoutPanelCaption="Error List"/><dxdo:LayoutPanelCaption="Output"/><dxdo:LayoutPanelCaption="Breakpoints"/></dxdo:TabbedGroup></dxdo:LayoutGroup><dxdo:LayoutPanelCaption="Solution Explorer"/></dxdo:LayoutGroup>

Auto-hide panels.

To create such panels, define an Auto-Hide Group with several panels.

[XAML]
<dxdo:DockLayoutManager.AutoHideGroups><dxdo:AutoHideGroupDockType="Left"><dxdo:LayoutPanelCaption="Toolbox"/><dxdo:LayoutPanelCaption="Server Explorer"/></dxdo:AutoHideGroup></dxdo:DockLayoutManager.AutoHideGroups>

How to: display axis labels between tickmarks

$
0
0
This example demonstrates how to display labels between tickmarks.
Viewing all 7205 articles
Browse latest View live


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