How to: Hide an Individual Series Label
How to import data in XAF
This example demonstrates how to import data from an XML-formatted text file, create business objects based on this data, validate them, and show the result in an XAF list view.
See also:
ORM Magic–Importing from any datasource
Note
This example cannot be automatically converted to VB.NET because of the VB.NET compiler limitations. We apologize for any inconvenience...
Question Comments
Added By: Tony Tadros at: 12/11/2012 4:51:05 AM
Hello Devexpress ,
do yo have any update about such functionality,do you have a plan to create or update current rows from excel as built in in the future
Added By: Dennis (DevExpress Support) at: 2/5/2013 10:55:49 PM@Tony: Here is a recent blog post on this functionality:
http://community.devexpress.com/blogs/eaf/archive/2012/12/29/orm-magic-importing-from-any-datasource.aspx
You can find more solutions in www.devexpress.com/issue=AS10553
Added By: Andreas Mummenhoff at: 8/22/2013 7:50:48 PMHello Dennis,
regarding VB conversion and porting to 13.1, here a short guide:
At first you have to fix one line in the C# project to convert it to 13.1
...
RuleSetValidationResult validationResult =
Validator.RuleSet.ValidateTarget(
nestedImportObjectSpace, obj, new ContextIdentifiers(DefaultContexts.Save.ToString()));
After that you can use a converter to create a VB solution.
Then in the VB project Dennis.ImportData, you have to fix the delegate definitions:
...
Public Delegate Function ImportDataDelegate(Of T)(
ByVal objectSpace As IObjectSpace, <[ParamArray]> ByVal args() As Object) As T
Public Delegate Function ValidateDataDelegate(Of T)(
ByVal data As T, <[ParamArray]> ByVal args() As Object) As Boolean
and at least you have to be correct in creating a delegate in
Public Shared Function CreateCoolPersonImportDataFromExcelDelegate() As ImportDataDelegate(Of Person)
Return Function(os As IObjectSpace, args() As Object) As Person
Throw New NotImplementedException("TODO: you can use the FileHelpers library to ...")
End Function
End Function
Then the project will run in VB too :-)
Added By: Fernando Minguet at: 6/16/2016 11:34:04 AM Is this implementation still based on UnitOfWork? I couldn't find any reference to UnitOfWork in the code, as found in K18260.Per K18260: "...The use of the XAF's ObjectSpace class is not recommended here because it is not as lightweight as the UnitOfWork."
Best Regards,
Added By: Dennis (DevExpress Support) at: 6/17/2016 8:22:11 AM @Fernando: I apologize for the confusion, because the K18260 article is outdated. We will consider updating it. It is also correct to use independent (that doesn't belong to a View) XPObjectSpace/XPNestedObjectSpace classes here and this approach is actually demonstrated in this example implementation.
GridView - Batch Editing - How to cancel editing or disable the editor conditionally
This example demonstrates how to cancel editing or disable the editor conditionally for the grid when batch editing is in use. It is possible to execute your logic either on the client or server side for a complex business model.
Then, handle the grid's client-side BatchEditStartEditing event to either cancel the edit operation using the e.cancel property:
[JavaScript]if(condition) e.cancel = true;
or disable the editor by obtaining its client instance:
[JavaScript]var editor = s.GetEditor(e.focusedColumn.fieldName); editor.SetEnabled(condition);
The custom server-side logic can be executed in the CustomJSProperties event handler:
[C#]settings.CustomJSProperties+=(s,e)=>{varclientData=newDictionary<int,object>();vargrid=sasMVCxGridView;for(inti= 0;i<grid.VisibleRowCount;i++){varrowValues=grid.GetRowValues(i,newstring[]{"ID","ServerSideExample"})asobject[];varkey=Convert.ToInt32(rowValues[0]);if(key% 2 != 0)clientData.Add(key,"ServerSideExample");}e.Properties["cp_cellsToDisable"]=clientData;};
See Also:
ASPxGridView - Batch Editing - How to cancel editing or disable the editor conditionally
Question Comments
Added By: Mohan Sundaram 1 at: 11/17/2014 2:14:05 PM
This is great example for conditional disable/cancel of cells. I'm trying to do the same for Insert vs Update in batch edit mode. How do I differentiate if its Insert or Update. Basically, I have a primary key column which I do not want the user to change while updating and should be available for typing it in while Inserting.
Added By: Anthony (DevExpress Support) at: 11/18/2014 4:00:36 AMHi Mohan,
It is possible to check a visible index of the editing row. If the index is negative, the row will be inserted. Otherwise, it is an update operation.
I need to know how can I set one row to not editable!! I want other rows to be editable!!
Added By: Anthony (DevExpress Support) at: 7/16/2015 2:45:03 AMHello,
To process your recent post more efficiently, I created a separate ticket on your behalf: T267677: GridView - Batch Editing - How to cancel editing a certain row. This ticket is currently in our processing queue. Our team will address it soon.
I must disable the row edit based on a value in a non-editable cell (EditFormSettings.Visible = DefaultBoolean.False), how can I do it?
e.rowValues does not contain this value.
How to display the Total value above each Pie Chart
How to display the Total value above each Pie Chart
This example demonstrates how to access the Underlying Pie Widgets used to display the Pie Item and configure their settings to display the Total value in the title. Total values are calculated automatically if the CalculateAllTotals property is enabled using the ConfigureItemDataCalculation event. To get the total value, the client-side ASPxClientDashboard.GetItemData method is used.
See Also:
Obtaining Underlying and Displayed Data
How to convert a Cartesian data shapefile to Geo coordinates
On creating a map, two types of coordinate systems are used: Cartesian coordinate and Geographic coordinate.
This example demonstrates how to open a shape file with Cartesian coordinates and save it to a shape file with Geo coordinates.
To convert Cartesian coordinates to Geo coordinates, MapControl requires information about the projection used in a shape file to represent a spherical surface in Cartesian coordinates. Refer to the Geographical Projections topic for additional information about projections. MapControl can load the required information from the projection (*.PRJ) file. If your data contains the *.PRJ file and this file is located in the same directory and has the same name as a shapefile, the coordinate system will be loaded automatically. Otherwise, if the paths or the names are different, call the ShapefileDataAdapter.LoadPrjFile method to load the coordinate system's metadata.
To convert a shape file with this example, run the project, then open a shape file and its projection file (if it has not been found automatically), and then save the map to a new shape file.
For additional information regarding this conversion, refer to the Provide Cartesian Data to a Geographical Map topic.
Web Dashboard - How to implement a custom TreeView Dashboard Item with Master Filtering to display hierarchical data
To learn how to work with custom items, refer to the T491984: Web Dashboard - How to create a custom dashboard item extension article.
Note: It is necessary to define three properties in the bindings section to display the tree view in this scenario: ID, ParentID, and Dimension. After that, the hierarchy will be created based on ID and ParentID relations and data from the Dimension field will be displayed.
How to implement a simple PDF viewer in ASP.NET WebForms web application by using the Document Server functionality
This example demonstrates how to implement a custom web PDF viewer control by using the DevExpress Document Server functionality.
The main idea of this approach is to use the PdfDocumentProcessor class functionality to load the PDF document and convert its pages to images. Then, these images are rendered in the browser to display PDF document pages.
Important Note:
The Document Server product license is required for using this approach. Please refer to the Subscriptions page for more information.
Question Comments
Added By: BJ Knudson at: 8/10/2017 2:23:33 PM Is there a way to implement this with scrolling pages, instead of the page index at the top?
How to provide drill-through functionality to web reports
To do this, implement the IWebDocumentViewerDrillThroughProcessor interface. In its CreateReport method, pass a DrillThroughContext instance and use its CustomData property to specify the navigation logic.
In this example, the CustomData value is compared against the NavigateUrl property values of report elements acting as links to open other reports.
To register a custom drill-through processor, call the RegisterWebDocumentViewerDrillThroughProcessor method of the DefaultWebDocumentViewerContainer class at the application startup.
Handle the client-side PreviewClick event of the Document Viewer to process mouse events related to report elements.
ASPxDateEdit - How to make the time section area responsive
This example demonstrates a simple approach to accessing the responsive time section area of the ASPxDateEdit control.
Responsive behavior is implemented via the CSS @media rule, which allows you to manipulate page elements depending on the screen resolution.
ASPxCardView - How to customize command buttons in individual cards and edit a DataTable
How to save and share custom view settings
In XAF applications, View settings are stored in Model Differences individually for each user. When the user changes the View (e. g., adds a column to a List View or groups View Items in a Detail View layout), these settings are saved in the user's Model Differences and applied to this View the next time it is displayed.
The built-in View Variants Module allows creating multiple predefined view settings using the Model Editor or in code and provides the end user with the capability to select a view variant at runtime.
Scenario
We want to provide the capability to save customized view settings as new view variants at runtime, share them, and allow any user having the corresponding permission to select a variant and apply these settings.
Solution
In this example, we use a persistent class to store view settings in the database and a view controller with actions to manage these settings (creating, applying and deleting). Each user can create his/her own view variants. Each view variant can be optionally marked as shared, so that other users can see and apply it to their views.
First, create the SettingsStore class with the following properties to store the View settings:
1. Xml - a string where serialized view settings are stored;
2. Name - the name of the View Variant;
3. OwnerId - an identifier of the user who created this Variant;
4. IsShared - specifies whether this Variant is shared with other users, or not;
5. ViewId - an identifier of the View for which this variant is created.
Then, create the ViewController with the following behavior:
1. There are Shared Model Settings available for each user, which cannot be edited by them.
2. Each user has his/her own default settings saved in the user's Model and used when there are no variants.
3. The SaveAsNewViewVariant action creates a new View Variant based on current view customizations. If this is the first Variant created for the view, two new Variants are created: a Variant that stores default settings (named "Default") and a Variant that stores customized view settings. If at least one Variant already exists, only the latter View Variant (with current customizations) is created. This variant becomes current.
4. The SelectViewVariant action makes the View Variant selected in the combo box current. This action is available when at least one variant exists. When the current View Variant is changed, customizations applied to the previous View Variant are lost. Only the "Default" View Variant customizations are saved in the Model when the current variant is changed.
5. The UpdateCurrentViewVariant action saves customizations to the currently selected View Variant.
6. The DeleteViewVariant action deletes the current View Variant. After deletion, the "Default" view variant becomes current and its settings are applied.
7. The UpdateDefaultViewVariant action saves customizations made to the current view in the "Default" Variant.
Actions provided by the ViewVariantsController controller may look as follows:
This example demonstrates the basic functionality, which you can expand or customize according to your requirements. For example, you can prevent certain users from deleting View Variants using the Security System facilities. Also, you can store the current Variant in the Model (see the Extend and Customize the Application Model in Code topic in our documentation) or in a property of the user object and apply it when the corresponding View is opened.
Note that the approach demonstrated by this example may be inappropriate or too complicated for certain use cases. So, we cannot guarantee that it will work in all possible scenarios. Should you face any issue using this solution or difficulty implementing it in your project, please submit a separate ticket and describe your scenario in detail. We will research this information to make the functionality better.
ASP.NET Pivot Grid - Getting Started - Bind a Pivot Grid to an OLAP Cube (Runtime sample)
ASPxDateEdit - How to make the time section area responsive
This example demonstrates a simple approach to accessing the responsive time section area of the ASPxDateEdit control.
Responsive behavior is implemented via the CSS @media rule, which allows you to manipulate page elements depending on the screen resolution.
PopupControl - How to implement a confirmation dialog that can be used everywhere in your application
For this task, you need to place a popup into Layout view and place the label and buttons there:
And write a simple JS function that will show this popup and assign the handler to the Yes button:[C#]@Html.DevExpress().PopupControl(settings=>{settings.SetContent(()=>{//label and buttons});}).GetHtml()
Then, you will be able to use the dialog as follows:[JavaScript](function(){'use strict'; window.dxConfirm = function(text){if(text && text.length) ConfirmLabel.SetText(text); ConfirmYes.Click.ClearHandlers(); ConfirmYes.Click.AddHandler(Hide); ConfirmPopup.Show();return{ success: function(onSuccess){ ConfirmYes.Click.AddHandler(onSuccess);}};};function Hide(){ ConfirmPopup.Hide();}})();
Here, the string parameter is the message that will be shown in the popup and the function passed to success defines the action that will be performed after Yes is clicked.[JavaScript]dxConfirm("Do you want to show an alert?").success(function(){ alert("success");});
If you pass an empty string, the default message will be shown. However, the success function is required as there is no point in using the dialog without it.
ASPxGridView - How to hide a detail grid's column when exporting a master-detail grid
This example illustrates how to make a detail grid's column visible in the master detail grid on the page and hide it when exporting the master grid.
To accomplish this task, it's necessary to set the corresponding detail grid column's Visible property to false in the detail grid's DataBound event handler only when exporting is performed. For this purpose, set a custom flag variable that indicates that the export is performed in your Export button's Click event handler. Then, check this variable's value in the detail grid's DataBound event handler and hide the required column if it's equal to true.
How to change row font after changing the focused row in the same manner used in Outlook
This example demonstrates how to change the row style after the row focus has been changed, e.g. in the manner used in Outlook when a message has been read.
ASPxGridView - How to implement select/unselect for all rows in a group row
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.
MVC version: T362032: GridView - How to implement select/unselect for all rows in a group row
See also
How to implement select/unselect for all rows in a group row in ASPxGridLookup
Question Comments
Added By: Colin Fryer 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 PMThis 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 PMHello 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.
I use 14.1.8 MVC Controls,
how can I select all rows in a group?
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.
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 PMHello,
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.
If you need a sample project demonstrating the same scenario for MVC, I suggest you refer to the GridView - How to use the link to select and deselect all rows in a group example which demonstrates the same task.Added By: Sabur Aziz at: 8/17/2017 1:33:53 AM Using this example, and grouping it by "Category Name" and "Supplier ID", whenever someone click on a either a "Category Name" or "Supplier ID" checkbox, how can I
1. detect which checkbox is selected/unselected
2. and at which level ("Category Name" level or "Supplier ID" level)
I've added the OnCheckedChanged event to the group's checkbox
<dx:ASPxCheckBox ID="checkBox" runat="server"
OnCheckedChanged="checkBox_CheckedChanged" />
But can't find a way to uniquely identify a checkbox when it's selected/unselected in the event
Please help.
How to save the currently opened View as a new View Variant at runtime
This example provides reusable UserViewVariants modules that allow your end-users to add View Variants dynamically. Refer to the Best practices of creating reusable XAF modules by example of a View Variants module extension blog post for more information. See functional tests for the implemented functionality in the UserViewVariants\Functional Tests\E2813.ets file.
IMPORTANT NOTES
Due to the application model generation specifics on the Web it makes sense to use this solution on the Web only if you store your end-user model differences in the database: How to store users' model differences separately for each user in the database.
See also:
How to save and share custom view settings
Question Comments
Added By: Robert Fuchs at: 9/2/2013 1:36:24 PM
Modified today but still not for 13.1 !?
Why?
Robert, this example was already available for version 13.1 before today. Today was just a maintenance update without much changes.
Added By: Robert Fuchs at: 9/3/2013 10:12:12 AMThanks Dennis.
Interestingly the version combo didn't show 13.1 yesterday.
I downloaded it anyway and it worked in 13.1 after changing .Net FW type to 4.
Hello, This is a great solution, but after upgrading to 13.2 it does not compile, Do you have a version for 13.2?
Thanks
Richard
waiting upgrade for 13.2
Added By: Willem de Vries at: 1/8/2014 8:49:14 AMJust leaving a comment to be included in any update messages. Waiting for a remedy for this breaking change to be able to upgrade to 13.2 with many of my applications.
Added By: Tony Tadros at: 1/14/2014 9:52:19 AMi have a suggestion to support such functionality of of the box
Added By: Stefan Tschiharz at: 1/23/2014 12:38:29 AMCould the example be updated to 13.2.6?
Added By: Dennis (DevExpress Support) at: 1/23/2014 12:41:45 AMGuys, please refer to my answer in Q554368 (there you can find an updated version + a link to a hot fix build).
Added By: Kanapol W. at: 1/29/2014 7:58:02 AMRight now, I have upgrade to v2013 vol 2.5
I use the most update code in "v2013 vol 1.4- v2013 vol1.9" . It get the error.
Would you please update this example to work with the most update version?
@Kanapol: This example will be updated once the version 13.2.7 is out (in a week or so). In the meantime, please check out my previous comment for a solution. Thanks.
Added By: Tony Tadros at: 12/23/2014 2:35:17 AMHello Devexpress ,
i have a need to use this module with a small change
i want to have 2 types of variants System,UserDefined for the system ones it should prevent users doing any changes on layout
or to discard changes after user closes current view
if i extended the IModelVariant with the property Type {System,User Defined}how to use this property to after
Thanks & Regards
Tony
@Tony: You can update the availability of the 'editViewVariantItem' and 'removeViewVariantItem' ChoiceActionItem objects of the Action based on your variant type information via the ChoiceActionItem.Active property:
This update can be done from within the UpdateUserViewVariantsAction method or on other events as you prefer.
As for discarding changes to a View, handle the View.ModelSaving event and set the Cancel parameter to True depending on your conditions. While we do not have a ready sample or guidelines for this particular customization, do not hesitate to contact us if you experience any difficulties using the XAF API I suggested above.
Dennis, it's very interesting example, thank you. I tested this solution in my project, that have implementation of storing user model in database. All One user modifications stored in database, but Other user have all One's modifications after login. Whats wrong, and how realy separate changes?
Added By: Dennis (DevExpress Support) at: 6/29/2015 6:31:30 AM@PTLab: Thanks for your feedback. To process your recent post more efficiently, I created a separate ticket on your behalf: T261243: E2813 and model differences stored in the database. This ticket is currently in our processing queue. Our team will address it as soon as we have any updates.
Added By: Mysoft Systems at: 1/7/2016 8:47:35 AMGreat Feature
Added By: Dennis (DevExpress Support) at: 1/8/2016 2:34:39 AM @Mysoft Systems: Thanks for your feedback. Would you please elaborate a bit more on the main functionality you are planning to implement for your project? With that, we can consider updates to this example or our built-in ViewVariants module to suit your business needs better. Thanks in advance.Added By: Paul Kubb at: 1/8/2016 2:39:02 AM@Dennis, May I join that? I have a certain business requirement about this too, which I still have no idea how to go.
Added By: Dennis (DevExpress Support) at: 1/8/2016 2:51:21 AM@Paul: Sure, we will be more than happy to learn more on your business requirements as well and support you with technical solutions. It's best to submit this info in a separate ticket as well.
As far as I understand, this is related to ViewVariants - How to show the ChangeVariant Action even for a single View variant where you have left a comment recently.
1. The example has a bug which leads to some errors: after deleting the current variant, the view is not changed. So we are in a context of not existing view and then executing e.g. New or Save&New in DetailViews lead to exceptions.
Solution - after deleting switch do the variants root view:
In DeleteViewVariant() method, replace the line "UpdateCurrentViewVariant(string.Empty);" with "UpdateCurrentViewVariant(GetRootViewId());"
2. There is also a second bug: when the Default variant is a current variant, then on entering the view the DeleteViewVariant choice action item is enabled (shouldn't be).
Solution:
Add the following code at the end of the UpdateUserViewVariantsAction() method:
"else UserViewVarintsAction.Items.FindItemByID(STR_DeleteViewVariant_Id).Enabled[STR_IsRootViewVariant_EnabledKey] = false;"
I would be happy if more of your customers had an active input to the solutions. It would help A LOT if you introduced "reputation" points for each user and also enhanced upvoting/downvoting, which is often disabled. (Can you please make a suggestion from this comment?)
Added By: Dennis (DevExpress Support) at: 1/18/2016 2:35:11 AMThanks for your suggestions, Krzysztof. In the meantime, you can leave comments in the code examples themselves or rather submit separate support tickets for the online documentation topics, KB Articles or code examples you are interested in.
Regardless of the current capabilities, we will take your input into account, though I cannot guarantee any implementation time frame, because there is actually a very small percentage of our customers who wish to contribute their time and experience to the existing learning materials. Previously, I was also thinking about re-hosting our code examples on GitHub so everyone could contribute to them easier. There is also http://www.expandframework.com/, which can be a good alternative.
>>Can you please make a suggestion from this comment?
Your comment here would already be sufficient for that purpose. Thanks.
How to save and share custom view settings
Your feedback on this implementation and the approach in general is welcome.
How to perform the Search operation for multiple locations
How to hide navigation items based on the current user
Our Security System allows hiding navigation items for certain users by configuring their Navigation permissions. These permissions can be configured in two modes.
Starting with version 16.2, Navigation Permissions can be assigned to individual navigation items. This feature is described in the Navigation Permissions section of the Security System Overview article. This feature is enabled by default in a new project created using the Wizard. To enable it when upgrading from an older version, it is necessary to set the SecurityStrategy.SupportNavigationPermissionsForTypes option to false. If the project is based on Entity Framework, it is also necessary to update the database. For this, use the approach described in this Knowledge Base article: How to: Add Navigation Permissions to an Entity Framework Application Created with XAF 16.1.
In version16.1 and older, navigation permissions can be assigned to a specific object type via the AllowNavigate option available in the Type Permissions settings. All navigation items specific to a corresponding type are removed from the navigation control if the current user does not have the permission for navigating to this type. This mode is enabled by default when upgrading an old project to version 16.2 and higher. To enable it in a new project created using the Wizard, open the application designer and change the SecurityStrategy.SupportNavigationPermissionsForTypes property value to false.
This example demonstrates how to implement the first mode manually. The approach demonstrated in this example is useful if the project uses an old XAF version that does not yet have the Navigation Permissions feature implemented.
Note: If you use the solution provided in this example and upgrade to version 16.2, this code may stop working properly. In this case, use recommendations provided at the end of this article.
If your XAF version is less than 16.2 and you need to grant permissions to individual navigation items (e.g., to a DashboardView or to a certain ListView model), use the solution described below to extend the Security System's functionality. In this example, the HiddenNavigationItems property allowing you to hide navigation items by their ID will be added to the role class.
The approach with overriding the ShowNavigationItemController.SynchItemWithSecurity method shown in this example can be also appropriate for tasks that are not related to the Security System directly. You can hide or customize any navigation item in this manner.
Steps to implement:
1. Implement a custom permission type - NavigationItemPermission - that can be used to check access permissions for a certain navigation item by its ID.
2. Implement a custom permission request - NavigationItemPermissionRequest - that will be sent to check whether the current user has access to a certain navigation item.
3. Implement a custom permission request processor - NavigationItemPermissionRequestProcessor - that will determine whether the current user has permissions for the received permission request.
4. Implement a custom role with the HiddenNavigationItems property. Extend it with the GetPermissions method to create NavigationPermission instances based on the value of the HiddenNavigationItems property.
5. Specify the custom role in the Security System's RoleType property in the Application Designer, as described in the How to: Implement Custom Security Objects (Users, Roles, Operation Permissions) topic.
6. Register your permission request processor in the application by handling the SecurityStrategy.CustomizeRequestProcessors event in the Program.cs and Global.asax.cs files.
7. Implement a ShowNavigationItemController's descendant - CustomShowNavigationItemController - and override its SynchItemWithSecurity method to deactivate navigation items prohibited by the CustomSecurityRole.HiddenNavigationItems property.
After implementing these steps in your project, you will be able to assign a role with the HiddenNavigationItems property to required users to restrict their access to certain navigation items.
Note: The example is based on the PermissionPolicyRole and PermissionPolicyUser classes. These classes are used by the Security System when selecting the Allow/Deny permissions policy in the Solution Wizard. If your project was created using an earlier XAF version (prior to 16.1), and the SecuritySystemRole and SecuritySystemUser classes are used in it, change the version number in the combo box below to see an example for these classes.
Upgrade note for version 16.2:
The code used in older versions of this example can stop working after upgrading to this version. To fix this issue, either copy the relevant code from the new version of the example, or modify the CustomShowNavigationItemController class by adding this method:
[C#]protectedoverrideboolSyncItemsWithRequestSecurity(DevExpress.ExpressApp.Actions.ChoiceActionItemCollectionitems){base.SyncItemsWithSecurity(items);returntrue;}
[VB.NET]ProtectedOverridesFunction SyncItemsWithRequestSecurity(ByVal items As DevExpress.ExpressApp.Actions.ChoiceActionItemCollection) AsBooleanMyBase.SyncItemsWithSecurity(items)ReturnTrueEndFunction
Question Comments
Added By: Maurice Picton at: 6/10/2014 7:52:32 AM
Can someone post the HideNavigationItemsExample that is mentioned below in the code?
I'm having trouble implementing this solution.
In the steps to implement, none of the entities you describe are in any of the documentation and I can't locate them in visual studio.
Added By: Anatol (DevExpress Support) at: 6/10/2014 8:07:44 AM These classes are implemented in this example. You can see their code below, under the comments. To download the complete example, use the Downloads - Example link at the right edge of this page.Added By: Randy Jean at: 2/13/2015 11:15:42 AMIs there a way to make this be least restriction has precedence. For instance, if I have a users role that hides navigation items and a direct role that does not hide, can the director role take precedence over the user role somehow?
Added By: Randy Jean at: 2/13/2015 11:33:21 AMthink I may have come up with a way to make this work. If I add a wildcard * to my HiddenNavigationItem then modify the IsGranted like so:
public override bool IsGranted(NavigationItemPermissionRequest permissionRequest) {
foreach (NavigationItemPermission permission in permissions.GetPermissions<NavigationItemPermission>()) {
if (permission.HiddenNavigationItem == permissionRequest.NavigationItem) {
return false;
} else if (permission.HiddenNavigationItem.Replace("*","") == permissionRequest.NavigationItem) {
return true;
}
}
return true;
}
This seems to do what I want. So I can have user with the restrictions but then override in Director with the wildcard character like this: AddressGroup*, Person_Varied*
Do you see any issues with this?
Added By: Anatol (DevExpress Support) at: 2/16/2015 6:16:18 AMI am not sure that this approach will work in all cases, since the GetPermissions method returns permissions from all user roles, and with your implementation the first permission always wins. So, it is better to set a boolean variable based on the permission's HiddenNavigationItem property and return this value after processing all NavigationItemPermission permissions.
Added By: Genesis Supsup 1 at: 8/7/2016 12:48:08 PM This example doesn't seem to work anymore on when using PermissionPolicyRoleBase in version 16.1+ ... any workaround?Added By: Anatol (DevExpress Support) at: 8/9/2016 1:15:00 PM I have updated the example - now it uses the PermissionPolicyRole and PermissionPolicyUser classes. The PermissionPolicyRole class does not have the GetPermissionsCore method, so it was necessary to add this method to the CustomSecurityRole class and call it in the SecurityStrategy.CustomizeRequestProcessors event handler to collect permissions of the current user manually.Added By: Konstantin B (DevExpress) at: 12/20/2016 6:19:11 AM With the version 16.2, you can grant or deny access for specific navigation items and groups in the Navigation Permissions tab of the PermissionPolicyRole Detail View (see Security - Restrict access to certain navigation items).I have applied this approach since long time V15+ and everything was working fine but now i upgraded to V16.2.3 and this logic is not working anymore. Could you please help me as it has affected my production apps.Added By: Alexey (DevExpress Support) at: 12/21/2016 10:47:15 AM
Hello Mohammed,
I've created a separate ticket on your behalf (T465421: E380 not working ).