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

NavBar - How to display the TreeView extension in the Group Content template in bound mode


How to set a selection state of a group based on its children selection

$
0
0

This example illustrates how to set a selection state of a group based on its children selection.

 

Place ASPxCheckBox to ASPxGridView's GroupRowContent template and handle ASPxCheckBox’ Load event. In this event handler, check if a row is selected. It is possible to get the check box' NamingContainer of the GridViewGroupRowTemplateContainer type and the container index. After that, iterate through the GroupRow child rows and set ASPxCheckBox’ CheckState property. To properly get the number of GroupRow ChildRows, disable the RowCache in ASPxGridView. It is neccessary to enable ASPxGridView's ProcessSelectionChangedOnServer property to process selection changes on the server side.

Also, refer to the How to implement select/unselect for all rows in a group row example for detailed information.

GridView - How to filter dates by the month

$
0
0

By default, GridView uses cell values for filtering. At the same time, the control can display custom text in cells. The solution is based on these aspects.

1. Add an unbound columns to display dates:

[C#]
settings.Columns.Add(column=>{   column.FieldName="Month";   column.ColumnType=MVCxGridViewColumnType.DateEdit;   column.UnboundType=DevExpress.Data.UnboundColumnType.Integer;   column.SettingsHeaderFilter.Mode=GridHeaderFilterMode.CheckedList;})

 Note, its UnboundType is Integer, but not DateTime. The column will contain the numbers of months.

Handle the CustomUnboundColumnData event to populate column cells by month numbers:

[C#]
settings.CustomUnboundColumnData=(sender,e)=>{   if(e.Column.FieldName=="Month")   {       DateTimevalue=(DateTime)e.GetListSourceFieldValue("C5");       e.Value=value.Month;   }};

 The C5 field is a real column in GridView. If you do not need to show it to an end-user, you can hide this column. However, it is required for getting unbound column data.


Now the unbound column displays month values. However, if you wish to show an end-user full dates, handle the CustomColumnDisplayText event and implement the following handler:

[C#]
settings.CustomColumnDisplayText=(sender,e)=>{   if(e.Column.FieldName=="Month")   {       DateTimerealValue=((DateTime)e.GetFieldValue("C5"));       e.DisplayText=realValue.ToString("dd MMM yyyy");   }};

 The data is returned from the bound C5 data column, but shown in the unbound column.


Finally, update the Header Filter items as demonstrated below:

[C#]
settings.HeaderFilterFillItems=(sender,e)=>{   if(e.Column.FieldName=="Month")   {       e.Values.Clear();       e.AddValue("January","1");       e.AddValue("February","2");       e.AddValue("March","3");       e.AddValue("April","4");       e.AddValue("May","5");       e.AddValue("June","6");       e.AddValue("July","7");       e.AddValue("August","8");       e.AddValue("September","9");       e.AddValue("October","10");       e.AddValue("November","11");       e.AddValue("December","12");   }};

GridView - How to export an image in the header along with the GridView extension data

How to build non-linear layout via LayoutControl

$
0
0

This example shows how to arrange items within a LayoutControl, forming a non-linear layout. To create a layout, items are combined into groups and the groups are combined into other groups.

Various group visual styles are demonstrated. Group 1 is rendered using the GroupBox visual style (the View property is set to GroupBox), which allows a header to be displayed. There is also a group that represents items as tabs (its View property is set to Tabs). Other groups are painted without a header and borders.

For Group 1, the collapsing feature is enabled via the LayoutGroup.IsCollapsible property, allowing an end-user to collapse the group's contents.

For the tabbed group and the group that displays Item 2 and Item 3, horizontal sizing is enabled via the LayoutControl.AllowHorizontalSizing attached property. Vertical sizing is enabled for Item 4 via the LayoutControl.AllowVerticalSizing attached property.

For items 1, 2, 3, 4 and 6, the VerticalAlignment property is set to Stretch. These items are stretched when the LayoutControl's height is changed. For Item 9 and Item 11, the HorizontalAlignment property is set to Left and Right, respectively. These items have a fixed width and are not stretched when the LayoutControl's width is changed.

How to change styles of labels for individual layout items

$
0
0

The following code shows how to change the styles of labels for individual layout items, or all of them. The style is changed via the LayoutItem.LabelStyle property.

Styles of layout items' labels can be customized via the LayoutItem.LabelStyle property. This example demonstrates two approaches to changing the LabelStyle property:
- for all layout items belonging to a container - via the container's LayoutGroup.ItemStyle property. In this example, this style specifies the blue foreground color for labels
- for individual layout items - directly via their LayoutItem.LabelStyle properties. In the example, this style, applied to the first layout item (Model), paints the item's label in red.

How to: Specify DataTemplate used to render labels of LayoutItems

$
0
0

The following code shows how to specify a DataTemplate used to render a label in a custom manner. In the example, the DataTemplate displays a colon after the label's text.

The DataTemplate is assigned to the LayoutItem.LabelTemplate property. The template is provided via the LayoutGroup.ItemStyle property of the LayoutControl, so it's applied to all layout items.

How to: Display items in FlowLayoutControl and enable maximization feature


How to: Use DockLayoutControl

How to: Implement the report management functionality by using GridReportManagerService

$
0
0
This example demonstrates how to use GridReportManagerService in conjunction with ReportManagerBehavior to provide the end-user with the ability to create and manage reports.

How to: Implement the report management functionality by using StandaloneReportManagerService

GridView - How to localize a column caption

$
0
0

This example illustrates how to localize a column caption by using the DisplayAttribute class from the System.ComponentModel.DataAnnotations namespace. Here is a code snippet that illustrates this:

[C#]
   [Display(Name="Date",ResourceType=typeof(Localization))]   publicDateTimeRegisterDate{get;set;}

Note that localized strings are retrieved from resx files located in the Views\Home\App_LocalResources directory. In addition, we use the DropDownList element to switch between the cultures dynamically.

A preferable approach to localize the predefined elements of our extensions (such as context menus, command buttons, etc.) is to use satellite assemblies: Localizing ASP.NET Controls via Satellite Resource Assemblies.


See Also:
T108044 - Best practices to change the current Culture in ASP.NET MVC Application using ComboBox Extension

How to allow end-users to set custom names for grid filters and save/restore these names when a grid layout is saved/restored

$
0
0

When an end-users applies any filter to a grid, this filter is shown in the Filter Panel. When the AllowMRUFilterList property is set to true, recently used filters can be accessed via the View's MRU Filter List. It is a convenient way to access previous filters. Since filters can contain multiple filter conditions, it is not always comfortable to search for a necessary filter in the MRU Filter List. This example illustrates how to provide an end-user with the capability to set custom short names for filters. This way, a custom filter name will be shown in the Filter Panel as well as in the MRU Filter List.

To implement this feature, we have created a custom FilterNameProvider class. Create this class object and pass your GridView to its constructor. Once it is done, set the FilterNameProvider.AllowSettingFilterNames property to true to enable this functionality.

Now, when you right-click a filter text in the Filter Panel, a context menu will be shown. Click the Save Filter As item to invoke FlyoutDialog. In this FlyoutDialog, you can enter a custom filter name for the current filter shown in the Filter Panel.

So, your end-user can now assign custom short names for filters. However, this information will be lost once you save and restore a grid layout. To save custom filter names with the grid layout, we use the XmlXtraSerializer.SerializeObjects method. We pass the current GridView together with a FilterNameProvider object to this method. FilterNameProvider has the GridFilters property of the List<GridFitlerItem> type, which is intended to be serialized. That is why this property is marked with the XtraSerializableProperty attribute. Note that properties of the GridFitlerItem class are also marked with this attribute.

To restore these filters, we use the XmlXtraSerializer.DeserializeObjects method. Since new GridFitlerItem objects will not be created automatically when this method is called, it is necessary to declare a special method at the FilterNameProvider class to allow you to create such objects manually. This method should have a name according to this pattern: “XtraCreate<PropertyName>Item”. That is why we call this method as XtraCreateGridFiltersItem

How to show the Context Menu in a group footer and set a group summary in a column

$
0
0

This example illustrates how to show the context menu in a group footer and set a group summary in a column.

To implement a custom Context Menu in a group footer, it is necessary to use ASPxPopupMenu and fill its items like in the Context Menu of a grid’s footer.
For this, get the clicked column's index and applied summaries to show the menu's checked items. Then, get item visibility of the Context Menu in the grid's footer and apply it to the custom Context Menu items.
To show the Context Menu in ASPxGridView, enable ASPxGridView's ContextMenu setting.

To get the clicked column's index and applied summaries, handle ASPxGridView’s PreRender and BeforeGetCallBackResult events, build and send a custom class name to the client side by using the GridViewDataColumn.GroupFooterCellStyle.CssClass property. This property includes a custom class name that contains an index and applied summaries of the clicked column. Handle ASPxGridView's client-side ContextMenu event to get the CssClass name by using htmlEvent’s target.classname property. After the custom class name is obtained, show a popup menu under the mouse pointer.
After that, handle ASPxClientPopupMenu's client-side PopUp event. Set the visibility and a checked state of menu items.

To set a checked state of a menu item, use applied summaries that were obtained earlier. 
To set the visibility of menu items like in the menu of the grid’s footer, do the following:
- Use the private ASPxClientGridView.GetFooterContextMenu method to get footer menu item information;
- Iterate through all menu items;
- Use the private ASPxClientGridView.GetItemServerState method to get a footer menu item's visibility and apply it to a custom menu item of the group footer. 

Handle ASPxClientPopupMenu's client-side ItemClick event and send an ASPxGridView callback with a column’s field name where the menu is shown and a clicked item name as parameters. Handle ASPxGridView's CustomCallBack event, parse these parameters there and apply the summaries.

Note: The private ASPxClientGridView.GetFooterContextMenu and ASPxClientGridView.GetItemServerState methods are used internally. Thus, they can be deleted or modified at any time without notification. It is necessary to check an application where this approach is used on every update of DevExpress controls until the functionality to create summary in the group footer is implemented out of the box.

How to: Generate NavBarControl Items from a Collection and Automatically Group Them Depending on a Field Value

$
0
0

In this example, it's demonstrated how to use the GroupDescription property to automatically group items generated from a collection. To accomplish this task, it's necessary to set GroupDescription to a property name by which items should be grouped.


Another solution to group items is to bind NavBarControl to a source that implements ICollectionView and specify GroupDescriptions:

[C#]
CollectionViewEmployees.GroupDescriptions.Add(newPropertyGroupDescription("Department"));

 

If you wish to specify ItemsSource for each group separately, use the approach demonstrated at How to: Generate NavBarControl Groups and Items from a Collection


How to: Generate NavBarControl Groups and Items from a Collection

$
0
0

In MVVM scenarios, it's often necessary to generate elements from a collection. NavBarControl provides such a capability via the ItemsSource property. In this example, each object corresponding to NavBarGroup contains a sub-collection of items which will be visualized by NavBarItems. This is sub-collection is bound to the NavBarGroup.ItemsSource property. 

If you wish to group items without specifying NavBarGroup.ItemsSource, use the approach demonstrated at How to: Generate NavBarControl Items from a Collection and Automatically Group Them Depending on a Field Value.

How to: Use Styles to Customize the Appearance of Groups and Items in NavBarControl

$
0
0

This example demonstrates how the appearance of groups and items can be customized at different levels within the NavBarControl by using specific style properties. To learn more about appearance customization, please refer to Styling View Content Elements.

Question Comments

Added By: Ueli Hilfiker at: 9/9/2015 8:17:04 AM    

It doesn't work at design time with VS2015 and DevExpress v15.1?

Error-message:
ArgumentException: "NavBarLayoutSettingsExtension" ist für "Setter.Value" nicht gültig. Unterstützt werden nur die MarkupExtension-Typen "DynamicResourceExtension" und "BindingBase" oder abgeleitete Typen.

translated to English:
ArgumentException: "NavBarLayoutSettingsExtension" is not valid for "Setter.Value". The only supported MarkupExtension types are "DynamicResourceExtension" and "BindingBase" or derived types.

Stacktrace:
  bei System.Windows.Setter.Seal()
  bei System.Windows.SetterBaseCollection.Seal()
  bei System.Windows.Style.Seal()
  bei System.Windows.StyleHelper.UpdateStyleCache(FrameworkElement fe, FrameworkContentElement fce, Style oldStyle, Style newStyle, Style& styleCache)
  bei System.Windows.FrameworkElement.OnStyleChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
  bei System.Windows.DependencyObject.OnPropertyChanged(DependencyPropertyChangedEventArgs e)
  bei System.Windows.FrameworkElement.OnPropertyChanged(DependencyPropertyChangedEventArgs e)
  bei System.Windows.DependencyObject.NotifyPropertyChange(DependencyPropertyChangedEventArgs args)
  bei System.Windows.DependencyObject.UpdateEffectiveValue(EntryIndex entryIndex, DependencyProperty dp, PropertyMetadata metadata, EffectiveValueEntry oldEntry, EffectiveValueEntry& newEntry, Boolean coerceWithDeferredReference, Boolean coerceWithCurrentValue, OperationType operationType)
  bei System.Windows.StyleHelper.ApplyTemplatedParentValue(DependencyObject container, FrameworkObject child, Int32 childIndex, FrugalStructList`1& childRecordFromChildIndex, DependencyProperty dp, FrameworkElementFactory templateRoot)
  bei System.Windows.StyleHelper.InvalidatePropertiesOnTemplateNode(DependencyObject container, FrameworkObject child, Int32 childIndex, FrugalStructList`1& childRecordFromChildIndex, Boolean isDetach, FrameworkElementFactory templateRoot)
  bei System.Windows.FrameworkTemplate.InvalidatePropertiesOnTemplate(DependencyObject container, Object currentObject)
  bei System.Windows.FrameworkTemplate.HandleBeforeProperties(Object createdObject, DependencyObject& rootObject, DependencyObject container, FrameworkElement feContainer, INameScope nameScope)
  bei System.Windows.FrameworkTemplate.<>c__DisplayClass0.<LoadOptimizedTemplateContent>b__5(Object sender, XamlObjectEventArgs args)
  bei System.Xaml.XamlObjectWriter.OnBeforeProperties(Object value)
  bei System.Xaml.XamlObjectWriter.Logic_CreateAndAssignToParentStart(ObjectWriterContext ctx)
  bei System.Xaml.XamlObjectWriter.WriteStartMember(XamlMember property)
  bei System.Xaml.XamlWriter.WriteNode(XamlReader reader)
  bei System.Windows.FrameworkTemplate.LoadTemplateXaml(XamlReader templateReader, XamlObjectWriter currentWriter)

Added By: Andrey K (DevExpress Support) at: 9/10/2015 4:58:02 AM    Hi,

I have created a separate ticket on your behalf in order to provide quicker and more efficient responses. We will answer you here: T288445: dxn:NavBarViewBase.LayoutSettings attached property doesn't work

Thanks,
Andrey

How to: Generate Flow Layout Control Items from a Collection

How to: Generate Tile Layout Control Items from a Collection

How to: Use Different Scrolling Modes in NavBarControl Groups

$
0
0

NavBarControl groups support three scrolling modes:
- Buttons. The Up and Down buttons are used.
- ScrollBar. ScrollBar is used 
- None. Scrolling is disabled.
To control scrolling in NavBarControl, use the ScrollingSettings.ScrollMode attached property. 
Note that you can specify scrolling mode for each group separately using the NavBarGroup.GroupScrollMode property.

Viewing all 7205 articles
Browse latest View live


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