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

Editing in a new window

$
0
0

This demo shows how to edit a record in a new window (in a separate aspx page).

See Also:
How to edit the ASPxGridView without the edit form
How to edit a persistent object's properties on a stand-alone edit form

Question Comments

Added By: ahmed zahran 2 at: 10/5/2015 8:16:13 AM    

thanx for reply but you solution just open a new edit page in new window but not modal and the modal is main purpose for me . thanx again

Added By: Vasily (DevExpress Support) at: 10/5/2015 10:37:56 AM    

Hello Ahmed,

To process your recent post more efficiently, I created a separate ticket on your behalf: T296898: Editing in a new modal window. This ticket is currently in our processing queue. Our team will address it as soon as we have any updates.


How to implement cascading lookups

$
0
0

This example demonstrates how to implement cascaded lookups. The main idea is to get the changed value of the first lookup and select data based on this value for the second lookup. It is necessary to perform the following steps:

1. Handle the dxLokup.valueChangeAction event of the first lookup;
2. In this event handler pass the selected value of the first lookup to the DataSource.filter method of a data source that is related to the second lookup.

See also:
OData Associations
ODataContext
dxLookup
ODataContext - How to filter data by a foreign key value

Question Comments

Added By: Jeffrey Hodgson at: 10/5/2015 12:14:31 PM    

The links I'm referring to are the following and the result of clicking on them is as below -

dxLokup.valueChangeAction - Document not found
DataSource.filter - Document not found
OData Associations - Document not found
ODataContext - Document not found
dxLookup - Document not found
ODataContext - How to filter data by a foreign key value - does link to something except DevExpress

This is DevExtreme I'm using NOT DevExpress.

Added By: Nikolai (DevExpress Support) at: 10/6/2015 12:33:46 AM    Hi Jeffrey,

Thank you for bringing this to our attention. I've fixed URLs of these links. Please test them and let me know your results.

How to implement the Rest service based on an ASP.NET WebAPI application

$
0
0

This example demonstrates how to implement the Rest service based on an ASP.NET WebAPI application.

See also:
How to configure ODataService for a DevExtreme HTML5/JS application
Creating a REST service using ASP.NET Web API
An Introduction To RESTful Services With WCF
How to implement CRUD operations with a DataSource

Question Comments

Added By: Nikolai (DevExpress Support) at: 10/6/2015 12:35:29 AM    Hi Matthias,

Please post your comments regarding this issue in the Accessing data source in dxDataGrid for updating Id from ControllerAction ticket.

How to repeat the Detail report band multiple times (a data-bound report)

$
0
0
If a report is unbound, you can specify how many times the Detail band content is printed through the XtraReport.PrintOptions.DetailCountOnEmptyDataSource property.

If a report is data bound, you can limit the number of times the Detail band is printed by using the DetailCount property.

Please note that the DetailCount property is designed to specify the maximum number (i.e., the limit) of times the Detail band is printed. In other words, if a data source contains one record, we cannot print it more than one time by using the DetailCount property.
We need to use the solution illustrated by this example. It demonstrates how to repeat a data source record depending on a value taken from another field. To achieve this, add an unbound DetailReportBand and control the number of copies using its ReportPrintOptions.DetailCountOnEmptyDataSource property.

How to dynamically build a persistent class from a DataSet and then bind it to the GridControl

How to implement a custom LookUpEdit supporting Server Mode

$
0
0

The current LookUpEdit version does not allow using Server Mode datasources. This example demonstrates how to create a custom editor that allows using them.

Question Comments

Added By: Andrew Thornton at: 7/19/2013 10:32:51 AM    

Hi,

Just upgraded to 13.1.5, and this no longer compiles. Quite a few undocumented things looked to have changed.
Can we have a 13.4/5 version that works please?

Thanks.

Added By: Justin Zeng at: 4/17/2014 4:32:51 AM    

It seems many problem, can this function to be support in new version ?

Added By: Ivan (DevExpress Support) at: 4/27/2014 10:42:28 PM    

Hi Justin,

We cannot guarantee that this functionality will be available in the latest version. For now, you can try to extend this example manually. If you face difficulties doing this, do not hesitate to contact us.

Added By: Viktor Faerman at: 5/9/2014 1:57:04 AM    

Hi Alex,

how to implement this custom editor with MVVM?
Thanks, Viktor

Added By: Michael Ch (DevExpress Support) at: 5/9/2014 4:14:02 AM    Hello,

I have created a separate thread for your questions: How to implement a custom editor from the E4560 example with MVVM. Please refer to it for future discussion.

Thanks,
Michael

Added By: David Lemieux at: 8/12/2015 10:09:43 AM    

This probably does the trick for standalone lookup editors, but I have doubts about using this inside a grid. If my understanding of both the code below and the grid's mechanics is correct, a query will be issued for each and every cell for which such an editor is present. Therefore, if you have 20 records on screen with five columns each having such an editor, that's a hundred of connections opening, querying and closing right there. And EVEN with just ONE column, it will still be under-performing when it will be sorted, grouped or filtered. Even for the non-virtualized rows.

This needs a proper solution. Urgently.

Added By: Ivan (DevExpress Support) at: 8/13/2015 3:01:37 AM    

David, you are correct. The editor we implemented in this example is not designed to be used inside GridControl. With the current implementation, a new source/context will be created for each visible grid cell. Please refer to my comment in the LookUpEdit - server mode support ticket, where I clarified our plans regarding this feature.

Added By: Alexei Corduneanu 2 at: 9/4/2015 7:27:11 AM    

I'm trying to use this approach together with WcfInstantFeedbackDataSource.
As SelectedItem I'm setting the Item I've saved in the database previously. And I'm having a problem with loading the LookUpEdit value back because I'm getting "Value cannot be converted" error. I guess it's happens because the Item is not present in the datasource.
What should be a correct way to load the value back to this control?

Added By: Ilya (DevExpress Support) at: 9/4/2015 12:30:46 PM    

Hello,

To process your recent post more efficiently, I created a separate ticket on your behalf: T286248: How to modify E4560 so it properly works with a WcfInstantFeedbackDataSource. This ticket is currently in our processing queue. Our team will address it as soon as we have any updates.

Added By: Alexei Corduneanu 2 at: 10/6/2015 7:57:35 AM    

How could I achieve multiple selection using this control?

Added By: Ilya (DevExpress Support) at: 10/6/2015 11:27:36 AM    

Hi,
I have extracted your inquiry into a separate thread: How to enable multiple row selection in the LookUpEdit implementing Server Mode (E4560). Let's continue the discussion there.

ASPxGridView - How to hide the detail button if the detail grid is empty

$
0
0

This example illustrates how to hide the detail button for "empty" detail rows using the server-side DetailRowGetButtonVisibility event

Question Comments

Added By: Luis Rodriguez 15 at: 10/6/2015 12:54:32 PM    

how could I use with sqldatasource?

Added By: Sergi (DevExpress Support) at: 10/6/2015 11:20:15 PM    

Hello,

To process your recent post more efficiently, I created a separate ticket on your behalf: T297564: ASPxGridView - How to hide the detail button if the detail grid is empty when using SqlDataSource. This ticket is currently in our processing queue. Our team will address it as soon as we have any updates.

dxDataGrid - How to implement a custom store with CRUD operations

$
0
0

The dxDataGrid binding using a CustomStore help topic and the A custom data source does not apply paging, filtering, sorting and grouping article describe how to implement a custom data source that loads data for a dxDataGrid . This example demonstrates how to make a custom store for the dxDataGrid widget manipulate data. For this purpose, we need to implement the insertupdate and remove methods in our custom store. Each of these methods will be called automatically by the widget. 

The insert method accepts a parameter that contains values for a new item. The update method accepts two parameters: the first one is a key value of the editing row, and the second one contains values of modified data fields. The remove method accepts a parameter that contains a key value of the deleted row. When a method is called, we need to send a corresponding request to our data service and pass the required parameters. We use jQuery.ajax for sending requests to our data service. This example can be tested with a data service from How to implement the Rest service based on an ASP.NET WebAPI application.


See also:
Deferred Object
jQuery.extend
How to implement CRUD operations with a DataSource
dxDataGrid - How to implement a custom store with CRUD operations (SQLite)
Question Comments

Added By: Matthias Klein at: 10/6/2015 11:05:23 AM    

Is this a typo in line 20? ("lebgth")

Added By: Matthias Klein at: 10/6/2015 12:05:10 PM    

I have a date field in my dxDataGrid. When I update or insert a row the date is in the Format: "Thu Oct 08 2015 20:55:06 GMT +0200)". How can I change the format in which the date fields will be transfered as data?

Added By: Nikolai (DevExpress Support) at: 10/7/2015 2:23:35 AM    Hi Matthias,

Thank you for bringing this to our attention. I've updated our code.

As for "date field in my dxDataGrid", I've created a new ticket regarding this issue. Please post your comments in the T297669: dxDataGrid passes the string interpretation of a Date value to insert/update methods of CustomStore ticket.

 


ASPxGridViewExporter - How to save a file to a disk

$
0
0
In addition to downloading a file via ASPxGridViewExporter.Write***ToResponse methods, it is possible to save the file to a disk to the specified location:
- Write ASPxGridView data to a MemoryStream object via ASPxGridViewExporter.Write*** (but not ASPxGridViewExporter.Write***ToResponse) methods.
- Save the populated MemoryStream object as a file (via standard System.IO methods) to the specified location where you have permissions to create files.

[C#]
usingSystem;usingSystem.Linq;usingSystem.IO;...using(MemoryStreammemoryStream=newMemoryStream()){ASPxGridViewExporter_Instance_Here.WriteXlsx(memoryStream);memoryStream.Seek(0,SeekOrigin.Begin);using(FileStreamfileStream=newFileStream(Full_File_Name_Here,FileMode.Create,FileAccess.Write)){memoryStream.WriteTo(fileStream);}}

[VB.NET]
Imports SystemImports System.LinqImports System.IO ...Using memoryStream AsNew MemoryStream() ASPxGridViewExporter_Instance_Here.WriteXlsx(memoryStream) memoryStream.Seek(0, SeekOrigin.Begin)Using fileStream AsNew FileStream(Full_File_Name_Here, FileMode.Create, FileAccess.Write) memoryStream.WriteTo(fileStream)EndUsingEndUsing

How to build a Bar UI in accordance with the MVVM pattern

$
0
0

In this example, we combined two approaches to build a Bar UI in accordance with the MVVM pattern: 
1. The first approach assumes using DXBar's Implicit Data Templates feature, which allows you to associate Data Templates with certain View Models implicitly.
2. The second approach is to explicitly assign templates to View Models by using the ...Template and ...TemplateSelector properties.
You can find detailed information about these approaches here.

Simple MVVM application with DXBars - Tutorial

$
0
0

This tutorial demonstrates how to implement a simple and flexible data management system by using the MVVM pattern for WPF platform.

Task
Implement a flexible data management system by using the MVVM pattern for WPF platform.

Input Data
A list of Person objects providing custom information (first name, last name, photo and email).

Additional Requirements
The management system should provide an ability to modify information on persons and add/delete persons. The system should prevent accidental modification of persons' data via visual controls.

Step 1. Creating Data Model.
First, we create a simple data model:

1. The Person class with a set of relevant fields:

[C#]
publicclassPerson{publicstringFirstName=string.Empty;publicstringLastName=string.Empty;publicUriPhoto=null;publicstringEmail=string.Empty;}

2. The Persons entity that is a collection of Person objects:

[C#]
publicclassPersons:ObservableCollection<Person>{}

3. Utility classes that help creating Person objects:

[C#]
publicstaticclassPersonCreator{publicstaticreadonlyPerson[]Person;staticPersonCreator(){Person=newPerson[4];Person[0]=newPerson(){//... };//... }}publicstaticclassPersonsCreator{publicstaticreadonlyPersonsPersons;staticPersonsCreator(){Persons=newPersons();foreach(PersonpersoninPersonCreator.Person)Persons.Add(person);}}

Step 2. Creating Form for Person Entity.
In this step we create a view model for the Person entity by using the MVVM pattern - the PersonViewModel class. This class implements the interaction between the data model and UI.

1. Create a base view-model class implementing the INotifyPropertyChanged interface

[C#]
publicclassViewModelBase:INotifyPropertyChanged{publiceventPropertyChangedEventHandlerPropertyChanged;protectedvirtualvoidOnPropertyChanged(stringpropertyName){if(PropertyChanged!=null)PropertyChanged(this,newPropertyChangedEventArgs(propertyName));}}

2. Create the PersonViewModel class by inheriting from ViewModelBase. The class declares properties which are in-sync with Person object's properties.

[C#]
publicclassPersonViewModel:ViewModelBase{publicStringFirstName{get{returnPerson.FirstName;}set{if(Person.FirstName==value)return;Person.FirstName=value;OnPropertyChanged("FirstName");}}publicPersonPerson{get;privateset;}publicPersonViewModel(Personperson){Person=person;}//... }

The PersonViewModel class also contains a non-model related property (IsReadOnly). This property prevents objects from being modified by an end-user.

[C#]
publicclassPersonViewModel:ViewModelBase{//...publicboolIsReadOnly{get{returnisReadOnly;}set{if(isReadOnly==value)return;isReadOnly=value;OnPropertyChanged("IsReadOnly");}}boolisReadOnly=false;//...}

3. Create a view form containing controls used to display and edit data.

[XML]
<UserControl...><!--...--><Grid><Grid.RowDefinitions><RowDefinitionHeight="*"/><RowDefinitionHeight="Auto"/></Grid.RowDefinitions><dxe:ImageEditSource="{Binding Photo}"IsReadOnly="True"/><StackPanelGrid.Row="1"Orientation="Vertical"HorizontalAlignment="Center"><WrapPanelHorizontalAlignment="Center"Margin="3"><TextBlockText="Fisrt Name:"VerticalAlignment="Center"/><dxe:TextEditText="{Binding FirstName, UpdateSourceTrigger=PropertyChanged}"IsReadOnly="{Binding IsReadOnly}"Margin="5,0,0,0"/></WrapPanel><WrapPanelHorizontalAlignment="Center"Margin="3"><TextBlockText="Last Name:"VerticalAlignment="Center"/><dxe:TextEditText="{Binding LastName, UpdateSourceTrigger=PropertyChanged}"IsReadOnly="{Binding IsReadOnly}"Margin="5,0,0,0"/></WrapPanel><WrapPanelHorizontalAlignment="Center"Margin="3"><TextBlockText="Email:"VerticalAlignment="Center"/><dxe:TextEditText="{Binding Email, UpdateSourceTrigger=LostFocus}"IsReadOnly="{Binding IsReadOnly}"Margin="5,0,0,0"/></WrapPanel></StackPanel></Grid><!--...--></UserControl>

4. A helper PersonViewModelCreator class creates a PersonViewModel and populates it with data:

[C#]
publicstaticclassPersonViewModelCreator{publicstaticreadonlyPersonViewModel[]PersonViewModel;publicstaticPersonViewModelDesignPersonViewModel{get{returnPersonViewModel[0];}}staticPersonViewModelCreator(){intlength=PersonCreator.Person.Length;PersonViewModel=newPersonViewModel[length];for(inti= 0;i<length;i++)PersonViewModel[i]=newPersonViewModel(PersonCreator.Person[i]){IsReadOnly=true};}}

Initialize the UserControl.DataContext property with the view-model provided by PersonViewModelCreator :

[XML]
<UserControlx:Class="DXBarsAndMVVM.Views.PersonView"xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"xmlns:dx="http://schemas.devexpress.com/winfx/2008/xaml/core"xmlns:dDx="http://schemas.devexpress.com/winfx/2008/xaml/core"xmlns:dxe="http://schemas.devexpress.com/winfx/2008/xaml/editors"xmlns:dxb="http://schemas.devexpress.com/winfx/2008/xaml/bars"xmlns:hlp="clr-namespace:DXBarsAndMVVM.Helpers"xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"xmlns:d="http://schemas.microsoft.com/expression/blend/2008"mc:Ignorable="d dDx"dDx:ThemeManager.ThemeName="Office2007Silver"d:DesignHeight="300"d:DesignWidth="300"d:DataContext="{x:Static hlp:PersonViewModelCreator.DesignPersonViewModel}"><!--...--></UserControl>

5. Add an additional visual control element (BarCheckItem) to the view form that will be bound to the PersonViewModel.IsReadOnly property

[XML]
<UserControl...><dxb:BarManager><dxb:BarManager.Items><dxb:BarCheckItemName="cbIsReadOnly"Content="Locked"IsChecked="{Binding IsReadOnly}"/></dxb:BarManager.Items><dxb:BarManager.Bars><dxb:Bar><dxb:Bar.ItemLinks><dxb:BarCheckItemLinkBarItemName="cbIsReadOnly"/></dxb:Bar.ItemLinks></dxb:Bar></dxb:BarManager.Bars><Grid><!--editor controls--></Grid></dxb:BarManager></UserControl>

6. To test the project, add the following code to the main window

[XML]
<Windowx:Class="DXBarsAndMVVM.MainWindow"xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"xmlns:vw="clr-namespace:DXBarsAndMVVM.Views"xmlns:hlp="clr-namespace:DXBarsAndMVVM.Helpers"Title="MainWindow"Height="350"Width="525"DataContext="{x:Static hlp:PersonViewModelCreator.DesignPersonViewModel}"><Grid><vw:PersonView/></Grid></Window>

Step 3. Creating Form for Persons Entity.

1. Create a PersonsViewModel object that is a collection of PersonViewModel objects. The PersonsViewModel class is inherited from the LockableCollection<PersonViewMode> class defined in the DevExpress.Xpf.Core library. This class allows you to temporarily lock change notifications by using the BeginUpdate and EndUpdate methods. The BeginUpdate method suppresses the CollectionChanged event until the EndUpdate method is called. Once the EndUpdate method is called, the CollectionChanged event is raised.

[C#]
publicclassPersonsViewModel:LockableCollection<PersonViewModel>{publicPersonsPersons{get;privateset;}publicPersonsViewModel(Personspersons){Persons=persons;}}

2. When the Persons model collection is changed, it should be synchronized with the PersonsViewModel.

[C#]
publicclassPersonsViewModel:LockableCollection<PersonViewModel>{publicPersonsPersons{get;privateset;}publicPersonsViewModel(Personspersons){Persons=persons;Persons.CollectionChanged+=newNotifyCollectionChangedEventHandler(OnPersonsCollectionChanged);SyncCollection();}protectedvirtualvoidOnPersonsCollectionChanged(objectsender,NotifyCollectionChangedEventArgse){SyncCollection();}protectedvoidSyncCollection(){BeginUpdate();Clear();foreach(PersonpersoninPersons)Add(newPersonViewModel(person));EndUpdate();}}

3. To allow a user to select a model, new Selected and SelectedIndex properties are introduced. In addition, an indexer property is added that allows you to get PersonViewModel objects by Person objects.

[C#]
publicclassPersonsViewModel:LockableCollection<PersonViewModel>{//...publicPersonViewModelSelected{get{returnthis[SelectedIndex];}protectedset{SelectedIndex=IndexOf(value);}}publicintSelectedIndex{get{returnselectedIndex;}set{value=IsValidSelectedIndex(value)?value:-1;if(selectedIndex==value)return;selectedIndex=value;OnSelectedIndexChanged();}}publicPersonViewModelthis[Personperson]{get{if(person==null)returnnull;foreach(PersonViewModelviewModelinthis)if(viewModel.Person==person)returnviewModel;returnnull;}}protectedvirtualvoidOnSelectedIndexChanged(){OnPropertyChanged(newPropertyChangedEventArgs("Selected"));OnPropertyChanged(newPropertyChangedEventArgs("SelectedIndex"));}boolIsValidSelectedIndex(intselectedIndex){returnselectedIndex>= 0 &&selectedIndex<Count;}intselectedIndex=-1;//...}

4. Now we create a view containing a ListBox control.

[XML]
<ListBoxx:Name="list"ItemsSource="{Binding}"SelectedIndex="{Binding SelectedIndex}"><ListBox.ItemTemplate><DataTemplate><StackPanelOrientation="Horizontal"><TextBlockText="{Binding FirstName}"/><TextBlockText="{Binding LastName}"Margin="15,0,0,0"/></StackPanel></DataTemplate></ListBox.ItemTemplate></ListBox>

5. A helper PersonsViewModelCreator class creates a PersonsViewModel and populates it with data:

[C#]
publicclassPersonsViewModel:LockableCollection<PersonViewModel>{publicPersonsViewModel(Personpersons):this(persons,null){}internalPersonsViewModel(Personspersons,Func<Person,PersonViewModel>creatingMethod){NewPersonCommand=newPersonsCommand(OnNewPersonCommadExecute);DeletePersonCommand=newPersonsCommand(OnDeletePersonCommadExecute,OnDeletePersonCommadCanExecute);CreatingMethod=creatingMethod;Persons=persons;Persons.CollectionChanged+=newNotifyCollectionChangedEventHandler(OnPersonsCollectionChanged);SyncCollection();}protectedvoidSyncCollection(){BeginUpdate();Clear();foreach(PersonpersoninPersons){PersonViewModelpersonViewModel;if(CreatingMethod!=null)personViewModel=CreatingMethod(person);elsepersonViewModel=newPersonViewModel(person);Add(personViewModel);}EndUpdate();if(SelectedIndex==-1 &&Count> 0)SelectedIndex= 0;}Func<Person,PersonViewModel>CreatingMethod=null;}publicstaticclassPersonsViewModelCreator{publicstaticreadonlyPersonsViewModelPersonsViewModel;staticPersonsViewModelCreator(){PersonsViewModel=newPersonsViewModel(PersonsCreator.Persons,CreatingMethod);}staticPersonViewModelCreatingMethod(Personperson){foreach(PersonViewModelpersonViewModelinPersonViewModelCreator.PersonViewModel)if(personViewModel.Person==person)returnpersonViewModel;returnnewPersonViewModel(person);}}

The following code sets a DataContext for a view.

[XML]
<UserControlx:Class="DXBarsAndMVVM.Views.PersonsView"xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"xmlns:dx="http://schemas.devexpress.com/winfx/2008/xaml/core"xmlns:dDx="http://schemas.devexpress.com/winfx/2008/xaml/core"xmlns:dxb="http://schemas.devexpress.com/winfx/2008/xaml/bars"xmlns:hlp="clr-namespace:DXBarsAndMVVM.Helpers"xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"xmlns:d="http://schemas.microsoft.com/expression/blend/2008"mc:Ignorable="d dDx"dDx:ThemeManager.ThemeName="Office2007Silver"d:DesignHeight="200"d:DesignWidth="200"d:DataContext="{x:Static hlp:PersonsViewModelCreator.PersonsViewModel}"><!--...--></UserControl>

6. Create a command class that implements the ICommand interface

[C#]
publicclassPersonsCommand:ICommand{publiceventEventHandlerCanExecuteChanged{add{if(canExecute!=null)canExecuteChanged+=value;}remove{if(canExecute!=null)canExecuteChanged-=value;}}publicPersonsCommand(Action<object>execute):this(execute,null){}publicPersonsCommand(Action<object>execute,Func<object,bool>canExecute){if(execute==null)thrownewArgumentNullException("execute");this.execute=execute;this.canExecute=canExecute;}publicboolCanExecute(objectparameter){if(canExecute==null)returntrue;returncanExecute(parameter);}publicvoidExecute(objectparameter){execute(parameter);}publicvoidRaiseCanExecuteChanged(){if(canExecuteChanged!=null)canExecuteChanged(this,EventArgs.Empty);}Action<object>execute;Func<object,bool>canExecute;eventEventHandlercanExecuteChanged;}

Create commands that are used to work with the Person collection:

[C#]
publicclassPersonsViewModel:LockableCollection<PersonViewModel>{publicPersonsCommandNewPersonCommand{get;privateset;}publicPersonsCommandDeletePersonCommand{get;privateset;}//...publicPersonsViewModel(Personspersons):this(persons,null){}internalPersonsViewModel(Personspersons,Func<Person,PersonViewModel>creatingMethod){NewPersonCommand=newPersonsCommand(OnNewPersonCommadExecute);DeletePersonCommand=newPersonsCommand(OnDeletePersonCommadExecute,OnDeletePersonCommadCanExecute);//...}protectedvirtualvoidOnNewPersonCommadExecute(objectparemeter){Personperson=newPerson(){FirstName="First Name",LastName="Last Name",};Persons.Add(person);Selected=this[person];}protectedvirtualvoidOnDeletePersonCommadExecute(objectparemeter){intselectedIndex=SelectedIndex;Persons.Remove(Selected.Person);if(IsValidSelectedIndex(selectedIndex))SelectedIndex=selectedIndex;elseif(selectedIndex>=Count)SelectedIndex=Count- 1;elseif(selectedIndex< 0)selectedIndex= 0;}protectedvirtualboolOnDeletePersonCommadCanExecute(objectparemeter){returnIsValidSelectedIndex(SelectedIndex);}//...}

7. Add visual elements (BarButtonItems) to the form and bind them to corresponding commands.

[XML]
<dxb:BarManager><dxb:BarManager.Items><dxb:BarButtonItemName="btNew"Content="New"Glyph="/DXBarsAndMVVM;component/Images/Icons/new-16x16.png"Command="{Binding NewPersonCommand}"/><dxb:BarButtonItemName="btDelete"Content="Delete"Glyph="/DXBarsAndMVVM;component/Images/Icons/close-16x16.png"Command="{Binding DeletePersonCommand}"/></dxb:BarManager.Items><dxb:BarManager.Bars><dxb:Bar><dxb:Bar.ItemLinks><dxb:BarButtonItemLinkBarItemName="btNew"/><dxb:BarButtonItemLinkBarItemName="btDelete"/></dxb:Bar.ItemLinks></dxb:Bar></dxb:BarManager.Bars><!--...--></dxb:BarManager>

Step 4. Building GUI

1. Add DXTabControl with two tabs to the main window. The first tab will allow a end-user to select a record (a Person object) while the second tab will be used to edit selected record's properties:

[XML]
<Windowx:Class="DXBarsAndMVVM.MainWindow"xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"xmlns:dx="http://schemas.devexpress.com/winfx/2008/xaml/core"xmlns:dDx="http://schemas.devexpress.com/winfx/2008/xaml/core"xmlns:dxb="http://schemas.devexpress.com/winfx/2008/xaml/bars"xmlns:vw="clr-namespace:DXBarsAndMVVM.Views"xmlns:hlp="clr-namespace:DXBarsAndMVVM.Helpers"xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"mc:Ignorable="dDx"dDx:ThemeManager.ThemeName="Office2007Silver"Title="MainWindow"Height="350"Width="525"DataContext="{x:Static hlp:PersonsViewModelCreator.PersonsViewModel}"><dx:DXTabControlSelectedIndex="0"><dx:DXTabControl.View><dx:TabControlMultiLineViewHeaderLocation="Bottom"/></dx:DXTabControl.View><dx:DXTabItemContent="{Binding}"Header="Persons"><dx:DXTabItem.ContentTemplate><DataTemplate><vw:PersonsView/></DataTemplate></dx:DXTabItem.ContentTemplate></dx:DXTabItem><dx:DXTabItemContent="{Binding Selected}"Header="{Binding Selected}"><dx:DXTabItem.HeaderTemplate><DataTemplate><StackPanelOrientation="Horizontal"><TextBlockText="Details:"/><TextBlockText="{Binding FirstName}"Margin="5,0,0,0"/><TextBlockText="{Binding LastName}"Margin="5,0,0,0"/></StackPanel></DataTemplate></dx:DXTabItem.HeaderTemplate><dx:DXTabItem.ContentTemplate><DataTemplate><vw:PersonView/></DataTemplate></dx:DXTabItem.ContentTemplate></dx:DXTabItem></dx:DXTabControl></Window>

2. Tabs contain PersonsView and PersonView objects. Each view defines its own BarManager with a Bar. So, when switching between tabs, you will see a bar within a tab page. It is handy to have a single bar at the top of the main form instead. This can be implemented by using DXBars merging features.
To accomplish this, add BarManager with a bar at the top of the main window.

[XML]
<dxb:BarManager><dxb:BarManager.Bars><dxb:Barx:Name="MainBar"Caption="Bar"/></dxb:BarManager.Bars><!--...--></dxb:BarManager>

Here is the complete code of the main window:

[XML]
<Windowx:Class="DXBarsAndMVVM.MainWindow"xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"xmlns:dx="http://schemas.devexpress.com/winfx/2008/xaml/core"xmlns:dDx="http://schemas.devexpress.com/winfx/2008/xaml/core"xmlns:dxb="http://schemas.devexpress.com/winfx/2008/xaml/bars"xmlns:vw="clr-namespace:DXBarsAndMVVM.Views"xmlns:hlp="clr-namespace:DXBarsAndMVVM.Helpers"xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"mc:Ignorable="dDx"dDx:ThemeManager.ThemeName="Office2007Silver"Title="MainWindow"Height="350"Width="525"DataContext="{x:Static hlp:PersonsViewModelCreator.PersonsViewModel}"><dxb:BarManager><dxb:BarManager.Bars><dxb:Barx:Name="MainBar"Caption="Bar"/></dxb:BarManager.Bars><dx:DXTabControlSelectedIndex="0"><dx:DXTabControl.View><dx:TabControlMultiLineViewHeaderLocation="Bottom"/></dx:DXTabControl.View><dx:DXTabItemContent="{Binding}"Header="Persons"><dx:DXTabItem.ContentTemplate><DataTemplate><vw:PersonsViewLoaded="PersonsView_Loaded"/></DataTemplate></dx:DXTabItem.ContentTemplate></dx:DXTabItem><dx:DXTabItemContent="{Binding Selected}"Header="{Binding Selected}"><dx:DXTabItem.HeaderTemplate><DataTemplate><StackPanelOrientation="Horizontal"><TextBlockText="Details:"/><TextBlockText="{Binding FirstName}"Margin="5,0,0,0"/><TextBlockText="{Binding LastName}"Margin="5,0,0,0"/></StackPanel></DataTemplate></dx:DXTabItem.HeaderTemplate><dx:DXTabItem.ContentTemplate><DataTemplate><vw:PersonViewLoaded="PersonView_Loaded"/></DataTemplate></dx:DXTabItem.ContentTemplate></dx:DXTabItem></dx:DXTabControl></dxb:BarManager></Window>

The code-behind class:

[C#]
publicpartialclassMainWindow:Window{publicMainWindow(){InitializeComponent();}voidPersonsView_Loaded(objectsender,RoutedEventArgse){PersonsViewpersonsView=(PersonsView)sender;MainBar.UnMerge();MainBar.Merge(personsView.ChildBar);}voidPersonView_Loaded(objectsender,RoutedEventArgse){PersonViewpersonView=(PersonView)sender;MainBar.UnMerge();MainBar.Merge(personView.ChildBar);}}

Conclusion
MVVM provides a flexible way to write complex GUI systems. This tutorial helps you understand the basic principles of writing applications by using the MVVM pattern. The use of the DXBars component will help you add an efficient navigation UI to your applications.

How to: use FolderBrowserDialogService

$
0
0
This example demonstrates how to use FolderBrowserDialogService.

How to provide the quick search functionality for PivotExcelFieldListControl (Customization Form with FieldListStyle="Excel2007")

$
0
0

This example illustrates how to add a search box to the field list control. 
Our PivotExcelFieldListControl uses the TreeViewFieldsPresenter component to show fields in a tree-like view. In this example, we create a TreeViewFieldsPresenter control descendant and implement the filtering functionality at its level.  The default TreeViewFieldsPresenter is replaced with our descendant via styles.

Important: The provided approach works when fields are grouped via User Folders. In OLAP mode, fields are grouped automatically. If fields are not grouped, PivotGrid uses another control (not TreeViewFieldsPresenter ) to manage hidden fields and custom style is not used.

Question Comments

Added By: Constant (DevExpress Support) at: 10/9/2015 2:42:04 AM    This solution works for the grouped field list. In the OLAP mode, fields are grouped in the customization form by default. In the traditional binding mode, it is possible to group fields manually by specifying the PivotGridField.DisplayFolder Property for all or just some of them. This solution also helps to simplify layout customization if a lot of fields are available. 

How to use custom EditSettings in GridControl

$
0
0
This example demonstrates how to create and use custom EditSettings with a custom editor in GridControl.
For this, we create a TextEditSettings class descendant with a custom EditFont property which is used to set the editor's FontFamily property. Then, we create a TextEdit class descendant. In the static constructor of the TextEditSettings class descendant, we call EditorSettingsProvider's RegisterUserEditor2 method with our TextEditSettings and TextEdit as parameters. After that, we override its AssignToEditCore method to set the editor's FontFamily value to the EditFont value.
Question Comments

Added By: WAGENHEIM Laurent at: 10/9/2015 1:52:08 AM    

Hi,

When using this snippet to make a CustomComboBoxEditSettings I get a NullReferenceException on editSettings.ApplyToEdit(this, true, EmptyDefaultEditorViewInfo.Instance);

If I comment this line of code, everything seems to work fine.

NB : using reflector it seems to crash in this function :

protected internal virtual void UnsubscribeToItemsProviderChanged()
{
   this.ItemsProvider.ItemsProviderChanged -= this.ItemsProviderChangedEventHandler.Handler;
}

Added By: Alexander S (DevExpress Support) at: 10/9/2015 4:28:07 AM    

Hello,

To process your recent post more efficiently, I created a separate ticket on your behalf: NullReferenceException occurs when custom EditSettings are being applied to the editor. This ticket is currently in our processing queue. Our team will address it as soon as we have any updates.

How to show files preview as a thumbnail in ASPxFileManager

$
0
0

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.


How to display a login view as a popup window during navigation between views

$
0
0

Starting with 14.2, please use this example.
This approach can be applied starting with 13.2.9. 

This example demonstrates how to check whether the user is logged in and display a login view when it is necessary during navigation.

It is necessary to perform the following steps to accomplish this task:

1. Add a new view and place a dxPopup in it.

2. Implement the required logic for this view in a corresponding view model.

3. Handle the HtmlApplication.initialized event. In this event handler, get the login view template using the HtmlApplication.getViewTemplate method and add the view to the view port. This will allow you to display its internal popup using options from its view model.

4. Bind the login view model to the view markup using Knockout.

5. Declare a global variable for determining when a user is logged in. In this example we set this option to false by default, and we will set it to true when a user is logged in. This variable can be accessed from any part of the application and we can change its value in the login view model.

6. Handle the HtmlApplication.navigating event. In this event handler, we can get a view info (see HtmlApplication.getViewTemplateInfo) for the navigated view and check user credentials if necessary. For this purpose, we added the secure option to those views that should not be displayed for unauthorized users. If the user unauthorized, we can call a method from the login view model to display dxPopup from the login view. Moreover, you can cancel navigation by setting the cancel parameter of the event handler to true.

See also:
How to send authenticated requests to the OData service

Question Comments

Added By: Alexandre Henriques at: 4/28/2014 7:36:44 AM    

How do I make this piece of code in version 13.2.7?

app.initialized.add(function() {
       var $view = app.getViewTemplate("LogOnPopup");
       $view.appendTo(".dx-viewport");
       LogOnAsPopupView.loggedOn = ko.observable(false);
       LogOnAsPopupView.logOnPopupViewModel = LogOnAsPopupView.LogOnPopup();
       ko.applyBindings(LogOnAsPopupView.logOnPopupViewModel, $view[0]);
   });

Added By: Nikolai (DevExpress Support) at: 4/28/2014 11:00:20 PM    Hi Alexandre,

I have created a separate ticket for this issue. Please post comments to the How to display a login view as a popup window during navigation between views (13.2.7) ticket.Added By: Faraz Faheem at: 6/1/2014 3:28:54 AM    

Im having error on initialized event. Error says 'Error: cannot ready property 'add' of undefined' on app.initialized.add(funtion() { line.

Please help me

Added By: Faraz Faheem at: 6/1/2014 3:52:38 AM    

I just upgraded my project to 13.2.9 by project converter and viola everything works.

Thanks for the self-explanatory post.

Added By: Nikolai (DevExpress Support) at: 6/2/2014 12:15:33 AM    You are always welcome, Faraz.Added By: Faraz Faheem at: 6/3/2014 7:56:19 AM    

Hi Nikolai,

With authentication implementation, my LogOn.js file looks like below
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
AESalesApp.LogOnPopup = function (params) {

   var viewModel = {
       userid: ko.observable(""),
       password: ko.observable(""),
       visible: ko.observable(false),
       authenticated: ko.observable(false),
       redirectParam: this.redirectParams,
       logOn: function () {

           var user = {
               Name: this.userid(),
               UserName: this.userid()
           };
        
           AESalesApp.UserDb.authenticateUser(user).done(function (data) {

               AESalesApp.loggedOn(true);

               AESalesApp.credentialStore.insert({
                id: 1,
                accessToken: "34234234234234234",
                expiry: 234,
                refreshToken: "134234234234234",
                name: "faraz"
                });

               if (viewModel.redirectParam) {
                   AESalesApp.app.navigate(viewModel.redirectParam.uri, viewModel.redirectParam.options);
               }
               viewModel.close();

           });
       
       },
       show: function (redirectParams) {
           viewModel.visible(true);
           viewModel.redirectParam = redirectParams;
       },
       close: function () {
           viewModel.visible(false);
           delete viewModel.redirectParam;
       }
   };

   return viewModel;
};
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
where:
AESalesApp.UserDb is CustomStore getting data from Web Api. It is working fine and data is coming back from authenticalUser call.

I am having 2 problems here.
1. Done function param 'data' is not getting results from authenticateUser function  
2. Popup is not closing down

Added By: Nikolai (DevExpress Support) at: 6/4/2014 2:40:03 AM    Hi Faraz,

I have created a separate ticket for this issue. Please post all comments in the How to implement authentication with a popup login viewAdded By: Jerther at: 11/28/2014 2:08:30 PM    

this line should be updated:

<div data-bind="dxTextBox:{ type: 'password', value: password }"></div>

with

<div data-bind="dxTextBox:{ mode: 'password', value: password }"></div>

Added By: Nikolai (DevExpress Support) at: 12/1/2014 3:52:34 AM    Hi Jerther,

Thank you for bringing this to our attention. I've updated this example.Added By: V.Mangione at: 12/4/2014 7:55:59 AM    

Hi, this sample doesn't appear to be working anymore on just released v 14.2.3
The popup stays hidden.

Added By: Nikolai (DevExpress Support) at: 12/5/2014 2:23:56 AM    Hi,

Starting with 14.2, please use this example.Added By: IMiron at: 10/9/2015 2:06:22 PM    

Hi,

Can you please tell me how this can be accomplished with the Angular approach?
A sample would be best.

Thanks,
Ionut.

Added By: Nikolai (DevExpress Support) at: 10/12/2015 1:38:07 AM    Hello IMiron,

The DevExtreme framework is based on KnockoutJS and jQuery. AngularJS has its own navigation mechanism. I suggest that you refer to Angular documentation and forums regarding this issue.

See also:
ngView
Routing & Multiple Views

How to implement select/unselect for all rows in a group row in ASPxGridLookup

$
0
0
This example demonstrates how to implement select/unselect for all rows in a group row.

 

First, place ASPxCheckBox and ASPxLabel into the ASPxGridLookup.GridViewProperties.Templates.GroupRowContent template.

Second, set the ASPxCheckBox.Checked property and the client-side ASPxCheckBox.ClientSideEvents.CheckedChanged event in the ASPxCheckBox.Load event handler.

In this example the ASPxLabel.Text is bound in the markup using Two-Way DataBinding.


See also
How to implement select/unselect for all rows in a group row

How to implement select/unselect for all rows in a group row

$
0
0

This example demonstrates how to implement select/unselect for all rows in a group row.

It's possible to implement this behavior only by using ASPXGridView 9.1. For more information, please refer to Add client- and server-side methods to obtain rows belonging to a certain group.

First, place ASPxCheckBox and ASPxLabel into the Grid.Templates.GroupRowContent template.

Second, set the ASPxCheckBox.Checked property and the client-side ASPxCheckBox.ClientSideEvents.CheckedChanged event in the ASPxGridView.HtmlRowPrepared event handler.

In this example the ASPxLabel.Text is bound in the markup using Two-Way DataBinding.

See also
How to implement select/unselect for all rows in a group row in ASPxGridLookup

Question Comments

Added By: Brian Dukes 2 at: 7/15/2013 8:39:14 AM    

I'm looking to do this exact thing in the latest 13.1.5 ASP.NET MVC controls -- How can this be done?

Added By: Gustavo Becerril at: 6/27/2014 4:38:28 PM    

This example doesn't take into account grouping by more than one field, it merely selects the first item of every subgroup. I'd love to find out if there's a not-so resource intensive way to select every item inside every subgroup.

Added By: Artem (DevExpress Support) at: 6/29/2014 11:36:17 PM    

Hello Gustavo,

I've moved your question to a separate thread created on your behalf: 
The E1760 example doesn't select all rows if ASPxGridView is grouped by several columns
Please refer to it for further correspondence.

Added By: Gherda Corrao at: 12/1/2014 3:29:29 AM    

I use 14.1.8 MVC Controls,
how can I select all rows in a group?

Added By: Mike (DevExpress Support) at: 12/1/2014 4:42:10 AM    

Hello Gherda,

To process your recent post more efficiently, I created a separate ticket on your behalf: T180839: E1760 for MVC - How to implement select/unselect for all rows in a group row. This ticket is currently in our processing queue. Our team will address it as soon as we have any updates.

Added By: rushdan . at: 1/20/2015 7:44:15 PM    

Sorry,

I do not understand about this example. Refer to the markup below :

         <Templates>
               <GroupRowContent>
                  <table>
                      <tr><td>
                           <dx:ASPxCheckBox ID="checkBox" runat="server" />
                      </td><td>
                           <dx:ASPxLabel ID="CaptionText" runat="server" Text='<%# GetCaptionText(Container) %>' />
                      </td></tr>
                  </table>
               </GroupRowContent>
           </Templates>

I don't see the ASPxLabel and ASPxCheckBox in the example.

Refer to the markup below, the checkbox only available for ASPxGridView.

<dx:GridViewCommandColumn ShowSelectCheckbox="true" VisibleIndex="0" />

Added By: Vladimir (DevExpress Support) at: 1/20/2015 11:21:49 PM    

Hello,

Since demonstrated controls are placed into the GroupRowContent template, they appear only when ASPxGridView data is grouped by one or several columns. Please group data in the example to see the result.

How to set GridColumn’s relative width

$
0
0

Currently, relative width is not supported in the GridControl out of the box. However, to achieve this functionality, the BandedViewBehavior can be used. Define columns in the BandedViewBehavior.ColumnDefinitions collection and use the BandedViewBehavior.Column attached property to specify a column.

How to generate row and cell styles using conditional expressions in WPF DXGrid

$
0
0

OBSOLETE. Starting from version 14.1, DXGrid introduces the built-in conditional formatting feature. See the Conditional Formatting article and the E983 - How to implement conditional formatting for rows ticket for details.

This example illustrates how to add the DXGrid behavior when you can use some conditional expressions and apply your custom style for cells and rows.

This functionality was implemented by an attached behavior for TableView which encapsulates all the functionality. In addition, this approach allows you to add new style options in XAML or in a code-behind file of your application.

We also added a new "Format Condition Editor" item to the column popup menu.

 
This item will show you a dialog window for adding new styles and deleting and editing existing styles.

Question Comments

Added By: Mark G Servidio at: 1/9/2013 6:26:06 PM    

Is there an example of this same functionality for Silverlight? We require an almost identical functionality for our users.

Added By: David Hsu 1 at: 10/14/2013 9:19:49 AM    

It was great to be able to customize appearance using expression. But I found the appearance didn't get updated when I check/uncheck "IsCompleted" field.

I added INotifyPropertyChanged to Task object. Also I switched to different row to make the data saved to underline data.

Added By: Andrey K (DevExpress Support) at: 10/13/2015 6:06:54 AM    Hi,

We accidentally discovered that your comments were out of scope of our Support Center for a long time. If these issues are still actual, please create corresponding tickets in our SC.

 

Thanks,

Andrey

Viewing all 7205 articles
Browse latest View live


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