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

How to handle the click on the drop-down arrow for the BarButtonItem

$
0
0

This example demonstrates how to respond to clicking on the BarButtonItem's drop-down button when the DropDown style is applied to the BarButtonItem component.

Question Comments

Added By: Samantha Tan at: 6/17/2014 6:06:21 PM    

this example not doing anything!


How to configure dxDataGrid with jQuery Approach

How to bind a Pie Map dashboard item to data in code

$
0
0
The following example demonstrates how to bind a Pie Map dashboard item to data in code.

How to bind a Bubble Map dashboard item to data and customize its palette

$
0
0
The following example demonstrates how to bind a Bubble Map dashboard item to data in code and customize its palette.

How to load a file on the callback of the ASPxGridView using the ASPxWebControl.RedirectOnCallback method

$
0
0

By default, it is impossible to load files on callbacks:
The Concept of Callbacks
However, there's a solution that allows you to overcome this problem. Our ASPxWebControl class has the RedirectOnCallback method that allows redirecting to another page during a callback. 
In our situation, we can create a specific "download" page and call a method which loads a file in the Page_Load event handler of this page. This sample shows how to load a file by clicking the custom ASPxGridView button using two approaches:
1.  Redirect to the load page on client side using the window.location.href property.
2.  Redirect to the load page on server side by the ASPxWebControl.RedirectOnCallback method. 

See also:
ASPxTreeList - How to download a file by clicking a custom command button
ASPxGridViewExporter - How to show content document in a new tab

WinForms End-User Designer - How to customize the data source wizard connections string storage

$
0
0

By default, the report connections list is populated based on the connections stored in the application configuration file. In any case,, the application configuration cannot be modified at runtime, that's why the report connections list is not changed when the Reports End-User Designer is used.

To initialize, save and restore the connection strings in the Reports End-User Designer, use the approach demonstrated in this code example.

The main idea of this approach is to create a custom connection storage service (the ConnectionStorageService class descendant). Also, the SqlDataConnection class descendant (CustomSqlDataConnection) is used in this example to customize the connection names in the connections list.

How to implement the paste from clipboard feature

$
0
0

It's possible to implement pasting multiple rows from clipboard to GridControl with the following approach:

- Detect Ctrl+V key combination in the GridControl.ProcessGridKey;

- Add the row data to GridControl if the corresponding row exists.

Note: the GridControl supports the "copying to clipboard" feature out of the box. See the GridView.CopyToClipboard method. To enable copying multiple row/cells, set the GridView.OptionsSelection.MultiSelect to true and GridView.OptionsSelection.MultiSelectMode to CellSelect.

See Also:

- How to implement the Copy/Paste feature

- How to copy selected rows to the clipboard

Question Comments

Added By: Geovany Kelly at: 6/18/2014 4:43:12 PM    

question, The gridView must be empty? without Columns?

How to implement multi-row editing in the ASP.NET ListView

$
0
0

The ASPxGridListEditor does not natively support multi-row editing. It is recommended to either use the single-row inline editing by setting the AllowEdit property of the ListView model to True in the Model Editor, or edit objects in a DetailView. The multi-row editing functionality is rarely required, but since our customers usually experience difficulties implementing it, I decided to create this example.

There are several examples on how to implement this functionality in the ASPxGridView without XAF. From my point of view, the How to perform ASPxGridView instant updating using different editors in the DataItem template example is the most appropriate for XAF, because:

- this approach can be easily implemented using runtime code

- we already use DataItem templates to show data in grid cells.


All functionality is implemented in a single controller - the MultiRowEditingController. It performs the following operations:

1. Creates an ASPxCallback control and adds it to a page. This control is used to send callbacks from client-side editors used in grid cells.

2. Replaces the default DataItemTemplate with a custom one (EditItemTemplate). The custom template is required to show editors for the user input in grid cells. This template is based on the DataItemTemplate class used in XAF by default. The only difference is that controls from this template are always in the Edit mode.

3. Assigns the client-side script that performs a callback when the value is changed to the editors added to grid cells via the custom DataItemTemplate. This is done in the editor's Init event handler, because at this moment, the NamingContainer that contains the key of the bound object is available.

4. Handles the callback sent from the client side and changes the value of a corresponding object's property.


I recommend that you review the following help topics for additional information:

Access Grid Control Properties
ASPxGridView.Templates Property
How to use custom ASPxGridView template in a Web XAF application


Important notes
We have not tested this solution under all possible scenarios, so feel free to modify and test the code to better suit your needs. It this approach does not meet your requirements, implement a custom List Editor or ViewItem based on a custom Web user control with the ASPxGridView control configured at design time, as you would do in a standard non-XAF ASP.NET application.

 

Question Comments

Added By: Yuriy Konytskyy at: 6/3/2013 3:44:39 AM    

I doesn't work in v12.2.10

Added By: Anatol (DevExpress Support) at: 7/1/2013 4:19:13 AM    

I have updated the example. Please see implementation details for version 13.1.

Added By: Sandro Welter (Intelligix) at: 7/5/2013 3:02:00 PM    

I'm getting the error below.

The error occurred:
     Type: NullReferenceException
     Message: Object reference not set to an instance of an object.
     Data: 0 entries
     Stack trace:

Added By: Anatol (DevExpress Support) at: 1/10/2014 8:32:12 AM    

The NullReferenceException issue is solved.

Added By: PHN at: 1/30/2014 10:55:55 AM    

Hi,
I have some modifications to support ASPxDateTimePropertyEditor,ASPxLookupPropertyEditor:

using System;
using System.Linq;
using System.ComponentModel;
using System.Web.UI;

using DevExpress.ExpressApp.Web.Editors.ASPx;
using DevExpress.Web.ASPxGridView;
using DevExpress.ExpressApp.Web;
using DevExpress.ExpressApp.Editors;
using DevExpress.Web.ASPxClasses;
using DevExpress.ExpressApp.DC;
using DevExpress.Web.ASPxCallback;
using DevExpress.ExpressApp.Model;
using System.Web.UI.WebControls;
using DevExpress.Web.ASPxEditors;
using DevExpress.Xpo;
using DevExpress.ExpressApp;

namespace WebExample.Module.Web
{
    [ListEditor(typeof(object), false)]
    public class MultiEditASPxGridListEditor : ASPxGridListEditor
    {
        const String CallbackArgumentFormat = "function (s, e) {{ {0}.PerformCallback(\"{1}|{2}|\" + {3}); }}"; // ASPxCallback, key, fieldName, value
        public MultiRowEditASPxGridListEditor(IModelListView model)
            : base(model) { }
        ASPxCallback callback;
        protected override object CreateControlsCore()
        {
            Panel panel = new Panel();
            callback = new ASPxCallback();
            callback.ID = ObjectTypeInfo.Type.Name + "aspxCallback1";
            callback.ClientInstanceName = ObjectTypeInfo.Type.Name + "_callback1";
            callback.Callback += new CallbackEventHandler(callback_Callback);
            panel.Controls.Add(callback);
            ASPxGridView grid = (ASPxGridView)base.CreateControlsCore();
            grid.HtmlDataCellPrepared += new ASPxGridViewTableDataCellEventHandler(grid_HtmlDataCellPrepared);
            panel.Controls.Add(grid);
            return panel;
        }
        
        void grid_HtmlDataCellPrepared(object sender, ASPxGridViewTableDataCellEventArgs e)
        {
            if (e.DataColumn is GridViewDataColumnWithInfo && IsColumnSupported(((GridViewDataColumnWithInfo)e.DataColumn).Model))
            {
                e.Cell.Attributes["onclick"] = RenderHelper.EventCancelBubbleCommand;
            }
        }

        protected override ITemplate CreateDataItemTemplate(IModelColumn columnInfo)
        {
            if (IsColumnSupported(columnInfo))
            {
                EditModeDataItemTemplate editModeTemplate = (EditModeDataItemTemplate)CreateDefaultColumnTemplate(columnInfo, this, ViewEditMode.Edit);
                editModeTemplate.PropertyEditor.ImmediatePostData = false;
                editModeTemplate.CustomCreateCellControl += new EventHandler<DevExpress.ExpressApp.Web.Editors.CustomCreateCellControlEventArgs>(editModeTemplate_CustomCreateCellControl);
                return editModeTemplate;
            }
            else
            {
                return base.CreateDataItemTemplate(columnInfo);
            }
        }
        
        void editModeTemplate_CustomCreateCellControl(object sender, DevExpress.ExpressApp.Web.Editors.CustomCreateCellControlEventArgs e)
        {
            if (e.PropertyEditor.Editor is ASPxWebControl)
            {
                e.PropertyEditor.Editor.Init += new EventHandler((s, args) => Editor_Init(s, args, e.PropertyEditor.Editor));
            }
            else if (e.PropertyEditor is ASPxLookupPropertyEditor)
            {
                ASPxLookupPropertyEditor editor = e.PropertyEditor as ASPxLookupPropertyEditor;
                editor.DropDownEdit.DropDown.Init += new EventHandler((s, args) => Editor_Init(s, args, e.PropertyEditor.Editor));
            }
            
        }

        void Editor_Init(object sender, EventArgs e,WebControl baseEditor)
        {
            ASPxWebControl editor = (ASPxWebControl)sender;
            editor.Init -= new EventHandler((s, args) => Editor_Init(s, args, baseEditor));
            // Uncomment to remove editors borders
            //editor.Border.BorderStyle = BorderStyle.None;
            GridViewDataItemTemplateContainer container = baseEditor.NamingContainer as GridViewDataItemTemplateContainer;
            var columnInfo = container.Column as GridViewDataColumnWithInfo;
            editor.SetClientSideEventHandler("ValueChanged", String.Format(CallbackArgumentFormat,
                callback.ClientInstanceName, container.KeyValue, columnInfo.Model.PropertyName, editor is ASPxDateEdit ? "s.GetText()" : "s.GetValue()"));
        }

        void callback_Callback(object source, DevExpress.Web.ASPxCallback.CallbackEventArgs e)
        {
            String[] p = e.Parameter.Split('|');
            Object key = TypeDescriptor.GetConverter(ObjectTypeInfo.KeyMember.MemberType).ConvertFromString(p[0]);
            IMemberInfo member = ObjectTypeInfo.FindMember(p[1]);
            Object value = null;
            if (typeof(IXPSimpleObject).IsAssignableFrom(member.MemberType))
            {
                Type memberKeyType = XafTypesInfo.Instance.FindTypeInfo(member.MemberType).KeyMember.MemberType;
                int index1 = p[2].LastIndexOf("(");
                int index2 = p[2].LastIndexOf(")");
                if (index1 > 0 && index2 > index1)
                {
                    string memberKeyText = p[2].Substring(index1 + 1, index2 - index1 - 1);
                    value = ObjectSpace.GetObjectByKey(member.MemberType, Convert.ChangeType(memberKeyText, memberKeyType));
                }
            }
            else
            {
                value = TypeDescriptor.GetConverter(member.MemberType).ConvertFromString(p[2]); ;
            }
            object obj = ObjectSpace.GetObjectByKey(ObjectTypeInfo.Type, key);
            member.SetValue(obj, value);
            ObjectSpace.CommitChanges();
        }

        private Type[] supportedPropertyEditorTypes()
        {
            return new Type[]{
                typeof(ASPxStringPropertyEditor),
                typeof(ASPxIntPropertyEditor),
                typeof(ASPxBooleanPropertyEditor),
                typeof(ASPxEnumPropertyEditor),
                typeof(ASPxDateTimePropertyEditor),
                typeof(ASPxLookupPropertyEditor)
            };
        }

        protected virtual bool IsColumnSupported(IModelColumn model)
        {
            if (model.GroupIndex >= 0)
            {
                return false;
            }
            foreach (Type type in supportedPropertyEditorTypes())
            {
                if (type.IsAssignableFrom(model.PropertyEditorType))
                {
                    return true;
                }
            }
            return false;
        }
        // Sorting and grouping are not supported
        protected override ColumnWrapper AddColumnCore(IModelColumn columnInfo)
        {
            ASPxGridViewColumnWrapper columnWrapper = (ASPxGridViewColumnWrapper)base.AddColumnCore(columnInfo);
            if (IsColumnSupported(columnWrapper.Column.Model))
            {
                columnWrapper.Column.Settings.AllowSort = DevExpress.Utils.DefaultBoolean.False;
                columnWrapper.Column.Settings.AllowGroup = DevExpress.Utils.DefaultBoolean.False;
            }
            return columnWrapper;
        }
    }
}

Added By: Anatol (DevExpress Support) at: 1/31/2014 12:04:45 AM    

Thank you for sharing your code. It looks good. I hope it will be useful for others.

Added By: Apostolis Bekiaris (DevExpress) at: 2/17/2014 7:12:23 AM    

Added in eXpandFramework 13.2.7.4

Added By: HEUNGGI LEE at: 6/4/2014 6:10:47 AM    

Hi,
Is it possible to set width length on each column in GridView? It is ugly...especially Character field grid width is too narrow ..

Added By: Anatol (DevExpress Support) at: 6/5/2014 7:42:58 AM    Yes, this is possible - see Adjust column width in listviews on the Web.Added By: HEUNGGI LEE at: 6/18/2014 9:48:18 PM    

Hi PHN,
I tried with your code but list grid view does not show correctly row items. Last row has same pointer with before last row item.


How to add a split layout for Tablets using DevExtreme mobile development

How to customize drawing of vector items on a map

$
0
0
This example illustrates how to customize vector items when they are drawn on a map.

For this, it's necessary to handle the MapControl.DrawMapItem event and provide new values for the event arguments object.

How to navigate through views by using NavBarControl control and NavigationFrame class

$
0
0

This example demonstrates how to implement navigation between views by using the NavBarControl control and NavigationFrame class.

Question Comments

Added By: Shabra J Dowson at: 5/15/2014 3:02:24 AM    

I have only been able to extract the code of the XAML to see the Design view for this sample.  It may suit our needs.   I can't run the project - I'm just downloading 13.2.9 version of the DX Components to upgrade my development environment

Added By: Andrew K (DevExpress Support) at: 5/15/2014 7:41:53 AM    

Hello,

I have checked this example, and it works correctly on my machine (I also have 13.2.9). Please clarify what problem you faced. Can't you open the downloaded example or can't build it?

Thanks,
Andrew

Added By: Shabra J Dowson at: 6/19/2014 7:47:04 AM    

This project gives this error in the Immediate Window when it is run.  Can you suggest how to correct this error please?
System.Windows.Data Error: 2 : Cannot find governing FrameworkElement or FrameworkContentElement for target element. BindingExpression:Path=; DataItem='NavigationFrame' (Name='frame'); target element is 'FrameNavigationService' (HashCode=11898202); target property is 'Frame' (type 'NavigationFrame')

How to preserve the XtraGrid view state in multi level master/detail

$
0
0

This example is an extension of example How to preserve the XtraGrid View state for a grid in master-detail mode. It stores view states of all existing nested grid views.

Question Comments

Added By: Glenn Holden at: 6/19/2014 12:13:58 PM    

This class is significantly different than the example which it is based on.  Could you provide a Form class to demonstrate how this RefreshHelperClass is implemented?

How to use the GridView extension in a Full Screen mode (100% browser Width and Height)

$
0
0

This example is based on recommendations from the E3940: How to use the ASPxPageControl control in a Full Screen mode (100% browser Width and Height) Code Central example.

It illustrates how to use this technique in an ASP.NET MVC application and resize a DevExpress ASP.NET MVC extension (for example, GridView) to occupy the entire browser window (a Full Screen mode):

/Views/Shared/_Layout.cshtml:

[CSS]
body,html{padding:0;margin:0;}

Main View:

[JScript]
<script type="text/javascript"> function OnInit(s, e){ AdjustSize(); ASPxClientUtils.AttachEventToElement(window, "resize", function(evt){ AdjustSize();});}function OnEndCallback(s, e){ AdjustSize();}function AdjustSize(){var height = document.documentElement.clientHeight; grid.SetHeight(height);}</script> @Html.Partial("TypedListDataBindingPartial", Model)

PartialView:

[C#]
@Html.DevExpress().GridView(settings=>{settings.Name="grid";settings.ClientSideEvents.Init="OnInit";settings.ClientSideEvents.EndCallback="OnEndCallback";...settings.Width=System.Web.UI.WebControls.Unit.Percentage(100);settings.Settings.ShowVerticalScrollBar=true;settings.SettingsPager.Mode=GridViewPagerMode.ShowAllRecords;}).Bind(Model).GetHtml()

See Also:
E1081: How to use the ASPxGridView control (with the enabled vertical scrollbar) in a Full Screen mode (100% browser Width and Height)
E3940: How to use the ASPxPageControl control in a Full Screen mode (100% browser Width and Height)

Question Comments

Added By: Daniel Gradwell 1 at: 6/19/2014 6:35:51 AM    

This code works fine on an MVC if you don't have a footer panel. However if you have a footer panel the gridview goes under the footer rather than just filling the content area,

Can you advise how to avoid this?

Thanks

Added By: Larry (DevExpress Support) at: 6/19/2014 12:57:08 PM    Hello,

I have created a separate ticket on your behalf to process your inquiry more effectively:

How to use the GridView extension in a Full Screen mode (100% browser Width and Height) when page has footer

Please refer to it for further correspondence.

How to implement the ASPxRibbon as an ASPxGridView customization panel

$
0
0

This example demonstrates how to use an ASPxRibbon in a Web User Control, which can be added to an ASPxGridView's TitleTemplate to represent a control panel for managing common GidView functions.

Due to ASPxGridView specifics, all actions performed with the control require a request to the server in order to take effect. All these requests are performed via callbacks except two operations: switching the control to edit mode and the export operation. These operations are executed via postbacks. For this purpose, we implemented a custom postback event handler.

Another important point is that since the ASPxRibbon is a control intended to be used primarily as a client side static component, it does not keep its state between requests to the server. So, it is necessary to handle saving and restoring of Ribbon items' state on each request. For this purpose, use an ASPxHiddenField.

Please note that in order to enable correct operation of the client side command handler, the following settings need to be adjusted and should not be overridden:

[C#]
ASPxGridView.SettingsBehavior.AllowFocusedRow=true;ASPxGridView.SettingsPager.Visible=false;

[VB.NET]
ASPxGridView.SettingsBehavior.AllowFocusedRow = true ASPxGridView.SettingsPager.Visible = false

Question Comments

Added By: Yorch at: 6/19/2014 4:24:54 PM    

how do you register the RaisePostBackEvent?

Added By: Yorch at: 6/19/2014 4:44:20 PM    

i tried the code on javascript and does not fire the RaisePostBackEvent on the server side.

ASPxGridView - How to change certain context menu items' visibility or their enabled state depending on both whether a corresponding row is selected and a part of its data

$
0
0

There are two general approaches: server-side and client-side. In both cases, firstly, it's necessary to create all of the menu items using the ASPxGridView.FillContextMenuItems event. After that, some of menu items can be made invisible or disabled depending on certain conditions. 


Server-side solution.
Handle the ASPxGridView.ContextMenuItemVisibility event and use its e.SetVisible and e.SetEnabled methods to show/hide or enable/disable items respectively.

Note that these methods have overloaded versions that allow one to change visibility or enabled state for a specific row or a specific column.
It's very important to set the ASPxGridViewBehaviorSettings.ProcessSelectionChangedOnServer property value to true. In this case, each time a row is selected or unselected, a callback will be sent to the server and context menu items will be recalculated. If this property value is set to false, the context menu won't be updated after selecting or unselecting a row on the client side.
So, this approach requires callbacks to be sent to the server each time the end-user selects or unselects a row. This is why the server-side approach is less preferable than the client-side one.

Client-side solution.
Since the grid's data isn't available on the client side, to hide or disable rows depending on certain data, we need to analyze that data on the server side to determine whether or not a row must be made invisible or disabled and pass this information to the client side. A good way to achieve this is to create a List<bool> object that would contain required information and pass it to the client side as a custom JavaScript property.
Then handle the ASPxClientGridView.ContextMenu event and use the e.menu property to get the ASPxClientPopupMenu object that represents the context menu. After that, you can use the e.menu.GetItemByName method to get a menu item and then the SetEnabled and SetVisible methods to enable/disable or show/hide items respectively.


In the example, there are three items in the context menu. The first of them is always visible and enabled; the second is always enabled, but visible only for selected rows; and the third one is always visible, but enabled only for selected rows that have a corresponding "Discontinued" field value set to "true". There are two pages in the example that demonstrate both the client-side and the server-side approaches.

Question Comments

Added By: Steve Mol at: 6/19/2014 11:46:56 PM    

For a hybrid approach, you can set the ASPxGridViewBehaviorSettings.ProcessSelectionChangedOnServer property value to false.  Then, handle the event on the Client-side.  If it is determined in the Client-side that the circumstances require the server to handle the event, set e.processOnServer to true.  In this way, anything that can be handled on the Client-side will be and no callback will occur.  But if the server is needed, the callback can be forced.

On the other hand, you can set the ASPxGridViewBehaviorSettings.ProcessSelectionChangedOnServer property value to true.  The Client-side event will still be called, and you can set e.processOnServer to false to cancel the callback.

Either approach should reduce the callback occurrences to only what is required.


Drag&drop items from one standalone GalleryControl to another one (extended)

Bind a grid to an ObjectDataSource with EnablePaging

$
0
0

The example demonstrates how to create ObjectDataSource with select parameters to allow ASPxGridView to perform paging and sorting using SQL queries to a database server. It is possible to enable server-side paging using the ASPxGridView.DataSourceForceStandardPaging property.


See also:
A possible implementation of IListServer interface to achieve Server Mode functionality
OBSOLETE: A possible implementation of IListServer interface to achieve Server Mode functionality in the GridView extension

How to establish association from one class to many classes

$
0
0

For instance, you have a class for File. This class will be used in more than one BO. Each BO would then have a listview of Files that are attached to the particular class.
To accomplish this, you can create a super class, say DomainObjectBase and then establish a one-to-many relationship between the File class. After that you can derive your BOs from the DomainObjectBase class and they will automatically get the parent's relationships.

Question Comments

Added By: Martin D. at: 6/21/2014 11:01:22 AM    

Is it possible - to also associate with different representations of "File" ?
So that DomainObject1 -> get's a collection of GetCollection<MyFile>("files")
and domainObject2 -> Get's a collection of GetCollection<PngFile>("files") ?

How to select detail rows on master row selection

$
0
0

This example shows how to select rows in a detail grid when the master row selection is changed.

Question Comments

Added By: JORGE PALACIOS 1 at: 2/13/2013 8:30:23 AM    

Buenos Dias, estoy haciendo un master detail con pagetab y necesito agregar un tab o page tab dentro de otro tab
cree el primer tab o pagetab y me corre sin problema pero al montar el segund tab me salen errores lo que quierp saber es si puedo colocar un tab dentro de otro o anidar tab dentro de tab

Added By: HESBIM at: 6/22/2014 2:53:16 AM    

This example does not select all detail rows when i select master row without expendrow. How can i do that?

Scheduler - Lesson 3 - How to Use Scheduler in complex views

$
0
0

When a Scheduler view is customized in a way more complex than just specifying the start date or decorating web element styles, you should pass the Scheduler settings to the corresponding overloads of the SchedulerExtension.GetAppointmentToInsert<T>, the SchedulerExtension.GetAppointmentsToUpdate<T> and the SchedulerExtension.GetAppointmentsToRemove<T> methods. Otherwise appointment display and operations may perform incorrectly.

This approach requires that the SchedulerSettings object is instantiated on server side and passed to the controller and to the view. So a special helper class SchedulerSettingsHelper is implemented that provides required settings for views and controllers within the application.

Question Comments

Added By: Oleg (DevExpress Support) at: 6/22/2014 11:35:25 PM    

Hello,

The NullReferenceException is raised while running this sample with version 14.1.3.

If you need to run this sample in version 14.1, please use the 14.1.4 (or newer) release.

Viewing all 7205 articles
Browse latest View live


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