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

How to apply conditional formatting to Pivot cells

$
0
0
The following example demonstrates how to apply conditional formatting to Pivot cells at different detail levels.
- The Value format condition (FormatConditionValue) is used to apply formatting to the first-level data cells.
- The Range Gradient condition (FormatConditionRangeGradient) is used to highlight the last-level data cells.
- The Color Range condition (FormatConditionRangeSet) is used to classify values of Grand Total cells.
- The Top-Bottom condition (FormatConditionTopBottom) highlights row field values corresponding to top 3 categories.

Advanced Banded View Layout with attached behavior

$
0
0

Update:
Starting with version 13.1, we implemented banded grid support out of the box. See the Using Bands to Create Multi-Row Layout article and the E4625 - How to: Create a Banded View example for more information. The solution below applies to versions prior to 13.1.

This example demonstrates how to create the banded view for the DXGrid with the attached behavior.

See T267411 - Advanced Banded View Layout with attached behavior for more information.

We have included this solution in the DevExpress.Xpf.Grid.v11.2.Extensions library shipped with the 11.2 major version. Refer to the GridDemo.BandedView demo module to see this feature in action.

How to use the NavBarControl in a MVVM application

$
0
0

This example demonstrates how to use the DXNavBar with MVVM pattern and generate groups and items from a collection. 

How to export GridDashboardItem to Excel using an intermediate report (WinForms)

$
0
0

This example demonstrates how to fetch data from the GridDashboardItem placed in the DashboardViewer class instance. To get data from the item, the DashboardViewer.GetItemData method is used. Please look at the static GridDashboardItemToDataTableHelper class. With a MultiDimensionalData class instance, it is possible to create columns (see the CreateColumnsByGridDashboardItem method) and fill a DataTable (see the AddRowsByGridDashboardItem method). This table will be further used in a report to perform the export. I used the report from the How to export the GridDashboardItem item data to Excel from a web solution example.

GridView - Batch Editing - How to cancel editing or disable the editor conditionally

$
0
0

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:

[JScript]
if(condition) e.cancel = true;

 or disable the editor by obtaining its client instance:

[JScript]
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 AM    

Hi 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.

Added By: Rajeev Raysad at: 7/15/2015 11:10:33 PM    

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 AM    

Hello,

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.

How to use the XPPageSelector with the GridControl

$
0
0

Scenario
This article illustrates how to use the XPPageSelector component to provide Pager functionally to the XtraGrid control. This functionality is useful when you need to show data in small portions.

Steps
1. 
Create a new Windows Forms Application.
2. Add DXperience ORM Data Model Wizard to the application and use the Generating Persistent Objects for Existing Data Tables  approach to generate persistent objects from an existing database.
3. Add the XPCollection component to a Form and set the ObjectClassInfo property to the generated persistent object type to populate this collection with required objects.
4. Add the XPPageSelector component to the Form and set the Collection property to XPCollection.
5. Add GridControl  to the Form and use the XPPageSelector as a data source.
6. Add two Buttons and a Label. These controls will be responsible for page navigation.
7. Handle Button.Click events and create a method, which will update Label text as shown in the Form1.xx file.

Important notes:
Please note that paging is not applicable to the XtraGrid, as the grid requires the entire collection to correctly apply any sorting, grouping or filtering. Therefore, grouping, sorting and filtering will only be applied to the current page when the grid is bound to the XPPageSelector component. We suggest that you use the Server Mode  feature instead.

See also:
Tutorial 1 - Your First Data-Aware Application with XPO
How to: Bind an XPCollection to the Grid  

Question Comments

Added By: Vikas Gupta 7 at: 11/28/2012 3:24:44 PM    

Thanks for the code - but it's not working for me - I have tables with Schema for ex: Business.Files
In the class I am using
namespace ForeSight.Business
{
    public class Files : XPLiteObject
    {
         int fFileID;
        [Key(true)]
        public int FileID
        {
            get { return FileID; }
            set { SetPropertyValue<int>("FileID", ref fFileID, value); }
        }
        ... and more fields
     }
        public Files(Session session) : base(session) { }
        public Files() : base(Session.DefaultSession) { }
        public override void AfterConstruction() { base.AfterConstruction(); }
}

I am setting up the xpoDefault connectionstring by
XpoDefault.ConnectionString = MSSqlConnectionProvider.GetConnectionString(@"localhost\sqlexpress", "DatabaseName");
The application runs but
The problem is each time it runs it creates a new table name in the database named dbo.Files (which obviously is empty) thus shows nothing....

I got your example application and created a similar application and verified the code - but found nothing abnormalities...

What am i doing wrong?
let me know if can get you more information thanks

Added By: khushbu bothra 1 at: 7/16/2015 3:09:37 AM    

When binding xpPageSelector1 as datasource  to grid control it is giving object reference error. Could you attach working project?

Added By: Alexey (DevExpress Support) at: 7/16/2015 3:17:42 AM    

Hello,

To process your recent post more efficiently, I created a separate ticket on your behalf: T267692: When binding xpPageSelector1 as datasource to grid control it is giving object reference error. This ticket is currently in our processing queue. Our team will address it as soon as we have any updates.

How to create a PropertyEditor based on the XtraRichEdit control

$
0
0

Take special note that this editor is intended to be used for a simple and most common scenario when only one text property in a Detail View is edited with the help of the XtraRichEdit control (RichEditControl). Other scenarios are not supported in this example and are required to be implemented manually. For example, if there are more than one property, edited with this editor in a Detail View, then there may be problems with merging in ribbons. See the B142856 issue for more detailed information.

Important Notes
1.
 Please take special note that this example is not a complete solution and is supposed to be further tested and modified by you according to your business requirements.

2. The standard XAF Save Action may be activated on the first load in this example, because the MS Word and XtraRichEdit RTF formats are different and thus the object receives a different value on the first value post. Once you save the value in the control's format, it will work as expected. See also the Problem with setting the RtfText in XtraRichEdit and ImmediatePostData with XtraRichEdit tickets for the details on how to improve tracking of changed values in the RichEditControl component.

 

See Also:
Implement Custom Property Editors
How to: Implement a Property Editor for Windows Forms Applications
XtraRichEdit Home
PropertyEditors - Support the XtraRichEdit control.

Question Comments

Added By: Willem de Vries at: 10/24/2012 7:25:46 AM    

After copying the necessary files to my project, i ran into an error in MergeRibbonDetailViewController. I changed the code slightly (in the test):

        private void Frame_TemplateChanged(object sender, EventArgs e) {
            UnMergeRibbon();
            mainRibbonControl = null;
            IClassicToRibbonTransformerHolder form = Frame.Template as IClassicToRibbonTransformerHolder;
            if (form != null && form.RibbonTransformer != null) {
                form.RibbonTransformer.Transformed += RibbonTransformer_Transformed;
            }
        }

How to apply conditional formatting to Grid cells using the Date Occurring format condition

$
0
0
The Date Occurring format condition (FormatConditionDateOccuring) allows you to apply formatting to date-time values of a specific date and/or date interval relative to today.
This example demonstrates how to apply conditional formatting to Grid cells whose values fall into one of the predefined intervals.

How to drag-and-drop GridView cell data to a RichEditControl document

$
0
0

This example illustrates how to drag-and-drop GridView cell data to a RichEditControl document . 

Handle GridView's MouseMove and MouseDown events to obtain the grid cell under the cursor position via the GridHitInfo object and get the cell's data.
Also, use the following RichEditControl events: DragOver and DragDrop. Most of the work is performed in the DragOver event handler. Here, you should update the RichEditControl.Document.CaretPosition property value according to the current mouse position (use the approach described in the How to: Obtain the Document Position under the Mouse Cursor article). In the DragDrop event, just insert the stored text to the caret position and call the RichEditControl.Focus method to focus the RichEditControl.

See also: How to perform drag-and-drop operation in a custom manner

How to force the CheckedListBoxControl to change the item's state only when user clicks in the Glyph area.

$
0
0

To accomplish this task, you need to implement the boolean property (allowChangeCheck) in the CheckedListBoxControl descendant, which defines whether changing the check state is allowed. You need to create your own ListBoxControlState descendant for the appropriate state based on the SelectionMode that you want to assign for the CheckedListBoxControl, and override its MouseUp method to change the value of the allowChangeCheck property.

SelectionMode.One - SingleSelectState,
SelectionMode.MultiSimple - MultiSimpleSelectState,
SelectionMode.MultiExtended - ExtendedMultiSelectState,
SelectionMode.None - UnselectableState

Then, override the OnchangeCheck method of the Checked ListBoxControl class and suppress further processing, if the allowCHangeCheck property is false.

Question Comments

Added By: Scott Wylie at: 7/16/2015 11:44:52 AM    

This code prevents the user from using the spacebar to toggle the checkbox.  How should this be changed to include this functionality and ONLY click the glyph to check using the mouse?

How to reset View customizations made by end-users

$
0
0

Scenario
A new Reset View Settings Action is added into the toolbar that allows end-users to reset customizations made in root Views (this approach is not suitable for nested ListViews).
This functionality can be helpful if your end-users break the default layout, and after that, they want to restore it back.

Steps to implement
1. Copy the ...\WinSolution.Module.Win\ResetSettingsViewController.xx file into YourSolution.Module.Win module project.


IMPORTANT NOTES

We do not currently provide an easy solution for the nested ListView. For now, I can only recommend the following solution to you: 1. Close the parent DetailView containing a required nested ListView; 2. Programmatically reset the associated nested ListView model using the ModelNode API shown in the current example; 3. Reopen the previously closed parent DetailView (depending on the situation you can consider using the Frame.SetView, XafApplication.ProcessShortcut or other suitable APIs of our framework).

See also:
How to save the currently opened View as a new View Variant at runtime

Question Comments

Added By: Juan Pallas Ribes at: 5/22/2015 4:24:40 AM    

I want to reset customizations in nested listviews, so I set targetViewNesting = Nesting.Any. After executing action in a nested listview, all objects are loaded, instead of objects related to the master object.

How can I reset customizations in nested listviews?

Thanks

Added By: Dennis (DevExpress Support) at: 5/22/2015 6:31:17 AM    

@Juan: This approach is not suitable for nested ListView, I am afraid. At the moment, I can only recommend you recreate the whole parent DetailView if you have updates to its nested ListView.
>>I want to reset customizations in nested listviews,
Would you please also describe your specific use-case scenarios from an end-user perspective? I am asking because there may be different technical solutions.

How to obtain data from a ChartDashboardItem instance and export it to Excel (WinForms)

How to export cell range to a DataTable

$
0
0

This example illustrates how you can export worksheet cell range to a System.Data.DataTable object.

The following steps are required:

1) Add a reference to the DevExpress.Docs.vX.Y.dll assembly to your project containing the SpreadsheetControl. Note that distribution of this assembly requires a license to the DevExpress Document Server or the DevExpress Universal Subscription.
2) Create the DevExpress.Spreadsheet.Export.DataTableExporter instance using the DevExpress.Spreadsheet.Worksheet.CreateDataTableExporter method.
3) Call the Export method of the DataTableExporter.

You can create an empty DataTable by using the CreateDataTable method of the DataTableExporter. The column names are obtained from headings of the cell range, and the column data types are extracted from cell data types of the first row of a range.
The DataTableExporter contains various options that enables you to specify how cell data are processed before storing them in a DataTable.

Question Comments

Added By: Juan Capiau - D at: 7/29/2014 6:55:38 AM    

I'm trying this example and the 'Export Worksheet Table Using Exporter Options' throws an error (Index was out of range) on Sub barButtonItemUseExporterOptions_ItemClick, line 'Dim range As Range = worksheet.Tables(0).Range'. i've tried multiple files, none work. If i select a range and export that (the 'Export Selected Range to Data Table') there is no problem. How can I fix this ?

System.ArgumentOutOfRangeException was unhandled
 HResult=-2146233086
 Message=Index was out of range. Must be non-negative and less than the size of the collection.
Parameter name: index
 ParamName=index
 Source=mscorlib
 StackTrace:
      at System.ThrowHelper.ThrowArgumentOutOfRangeException()
      at DevExpress.XtraSpreadsheet.API.Native.Implementation.NativeCollectionBase`3.get_Item(Int32 index)
      at ExportToDataTableExample.Form1.barButtonItemUseExporterOptions_ItemClick(Object sender, ItemClickEventArgs e) in C:\Users\JCA\Documents\Samples\XtraSpreadSheet\14.1.5\E4997\ExportToDataTableExample\ExportToDataTableExample\Form1.vb:line 68
      at DevExpress.XtraBars.BarItem.OnClick(BarItemLink link)
      at DevExpress.XtraBars.BarBaseButtonItem.OnClick(BarItemLink link)
      at DevExpress.XtraBars.BarButtonItem.OnClick(BarItemLink link)
      at DevExpress.XtraBars.BarItemLink.OnLinkClick()
      at DevExpress.XtraBars.BarButtonItemLink.OnLinkClick()
      at DevExpress.XtraBars.BarItemLink.OnLinkAction(BarLinkAction action, Object actionArgs)
      at DevExpress.XtraBars.BarButtonItemLink.OnLinkAction(BarLinkAction action, Object actionArgs)
      at DevExpress.XtraBars.BarItemLink.OnLinkActionCore(BarLinkAction action, Object actionArgs)
      at DevExpress.XtraBars.ViewInfo.BarSelectionInfo.ClickLink(BarItemLink link)
      at DevExpress.XtraBars.ViewInfo.BarSelectionInfo.UnPressLink(BarItemLink link)
      at DevExpress.XtraBars.Ribbon.Handler.BaseRibbonHandler.OnUnPressItem(DXMouseEventArgs e, RibbonHitInfo hitInfo)
      at DevExpress.XtraBars.Ribbon.Handler.BaseRibbonHandler.OnUnPress(DXMouseEventArgs e, RibbonHitInfo hitInfo)
      at DevExpress.XtraBars.Ribbon.Handler.BaseRibbonHandler.OnMouseUp(DXMouseEventArgs e)
      at DevExpress.XtraBars.Ribbon.Handler.RibbonHandler.OnMouseUp(DXMouseEventArgs e)
      at DevExpress.XtraBars.Ribbon.RibbonControl.OnMouseUp(MouseEventArgs e)
      at System.Windows.Forms.Control.WmMouseUp(Message& m, MouseButtons button, Int32 clicks)
      at System.Windows.Forms.Control.WndProc(Message& m)
      at DevExpress.Utils.Controls.ControlBase.WndProc(Message& m)
      at DevExpress.XtraBars.Ribbon.RibbonControl.WndProc(Message& m)
      at System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m)
      at System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m)
      at System.Windows.Forms.NativeWindow.DebuggableCallback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)
      at DevExpress.Utils.Win.Hook.ControlWndHook.CallWindowProc(IntPtr pPrevProc, IntPtr hWnd, Int32 message, IntPtr wParam, IntPtr lParam)
      at DevExpress.Utils.Win.Hook.ControlWndHook.WindowProc(IntPtr hWnd, Int32 message, IntPtr wParam, IntPtr lParam)
      at System.Windows.Forms.UnsafeNativeMethods.DispatchMessageW(MSG& msg)
      at System.Windows.Forms.Application.ComponentManager.System.Windows.Forms.UnsafeNativeMethods.IMsoComponentManager.FPushMessageLoop(IntPtr dwComponentID, Int32 reason, Int32 pvLoopData)
      at System.Windows.Forms.Application.ThreadContext.RunMessageLoopInner(Int32 reason, ApplicationContext context)
      at System.Windows.Forms.Application.ThreadContext.RunMessageLoop(Int32 reason, ApplicationContext context)
      at System.Windows.Forms.Application.Run(Form mainForm)
      at ExportToDataTableExample.Program.Main() in C:\Users\JCA\Documents\Samples\XtraSpreadSheet\14.1.5\E4997\ExportToDataTableExample\ExportToDataTableExample\Program.vb:line 45
      at System.AppDomain._nExecuteAssembly(RuntimeAssembly assembly, String[] args)
      at System.AppDomain.ExecuteAssembly(String assemblyFile, Evidence assemblySecurity, String[] args)
      at Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()
      at System.Threading.ThreadHelper.ThreadStart_Context(Object state)
      at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
      at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
      at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
      at System.Threading.ThreadHelper.ThreadStart()
 InnerException:

Added By: Brian (DevExpress) at: 7/29/2014 7:25:34 AM    Please make sure that the document loaded in the SpreadsheetControl has a table. If it does not, insert a table using the Insert Table command in the Insert ribbon group, or use the Spreadsheet API as described in the How to: Create a Table document.Added By: Juan Capiau - D at: 8/1/2014 7:04:15 AM    

Not sure we're talking about the same thing. there is also no 'insert table' command or an insert ribbon group. Either i'm missing something basic (which is entirely possible) or the example is not complete. i'd like to understand the functionality and since this is an example that is supposed to do just that.... if you can assist, i'd appreciate it.

Added By: Ted (DevExpress Support) at: 8/4/2014 12:53:39 AM    

Hello Juan, 

I have extracted your original message with an exception description to a separate ticket - T136499: ArgumentOutOfRangeException is raised in the E4997 example. Our team will address it as soon as possible. 

How to customize PrintDialog and show the default .Net PrintDialog

$
0
0

This example illustrates how to customize PrintDialog in PrintPreview.

 

Note :

To show the default .Net Print Dialog instead of our PrintDialog, execute the following code :

 

[C#]
PrintDialogRunner.Instance=newSystemPrintDialogRunner();

 

How to customize a data store schema for SQL data sources

$
0
0

This example demonstrates how to customize a data store schema for a dashboard data source that uses a connection to the Northwind database.


In this example, the IDBSchemaProvider interface is implemented by a class that defines a custom data store schema containing two related tables. The GetSchema method returns tables and columns which will be included to a data store schema. 


To see the result, add a new query or edit the existing query.

Question Comments

Added By: Mariusz Muszalski at: 2/16/2015 3:31:54 AM    

I use ConfigureDataConnection event to provide connection details for my dashboard designer. The data source is OLAP (tabular). Can I use solution above to customize names of fields in field chooser?

Added By: Andrew Aks (DevExpress) at: 2/16/2015 5:29:48 AM    

This approach can be used only for SQL data sources. We will update the Provide a way to localize OLAP cube structure in Dashboard Designer request when a similar capability is added for OLAP data sources.


How to generate bands based on a collection in GridControl

$
0
0

To generate bands from a collection, we created a custom attached behavior with the BandsSource property. Bind this property to a collection of simple objects and specify the BandTemplate property that is used to visualize a band from an object. In a similar manner, you can use the ColumnsSource, ColumnTemplate and ColumnTemplateSelector properties to create columns in a band.

Editing an in-memory dataset

How to insert, edit and delete data in a data table by using ASPxGridView at runtime when data is stored in ViewState

$
0
0

This example shows how to insert, edit and delete data in a data table by using ASPxGridView. The data table and the grid are created at runtime.
To be able to store data in ViewState, the ASPxGridView.EnableCallBacks property should be set to False. Refer to the K18387: The Concept of Callbacks article for additional details.

See Also:
KA18686: ASPxGridView - How to implement CRUD operations with a custom data source
T191009: How to insert, edit and delete data in a data table by using ASPxGridView at runtime when data is stored in Session
Editing an in-memory dataset

How to automatically create mail-merge documents using the Snap Document Server

$
0
0

This example demonstrates how to use the Snap API to automatically generate master-detail mail merge documents by the DevExpress Snap Document Server.

After running this example, a console application creates a document that is exported to an RTF file and opened by default program.

See also: How to provide custom separators for records of a mail-merge document.

Question Comments

Added By: Alexandros Pappas 1 at: 7/21/2015 12:05:58 AM    

Can you please explain how you create the template.snx file?

Added By: George (DevExpress Support) at: 7/21/2015 4:17:38 AM    

Hi,

To process your recent post more efficiently, I created a separate ticket on your behalf: T269397: How to create a template.snx file. This ticket is currently in our processing queue. Our team will address it as soon as we have any updates.

 DashboardDesigner - How to customize data source wizard to display only predefined data connections

$
0
0

This example demonstrates how to use the DashboardDesigner.DataSourceWizardCustomization to replace the default pages of the data source wizard with custom ones:

[C#]
dashboardDesigner1.DataSourceWizardCustomization=newDataSourceWizardCustomization();

 

We use following code to skip first page which allows selecting the data source type, and specify custom a wizard page that allows selecting one of the predefined connections. This custom page does not allow establishing a new connection:

[C#]
publicclassDataSourceWizardCustomization:IDashboardDataSourceWizardCustomization{publicvoidCustomizeDataSourceWizard(IWizardCustomization<DashboardDataSourceModel>customization){customization.StartPage=typeof(ChooseConnectionPage<DashboardDataSourceModel>);customization.Model.DataSourceType=DashboardDataSourceType.Xpo;customization.RegisterPageView<IChooseConnectionPageView,CustomChooseConnectionPageView>();}}

 

To specify default connections in code behind, use the DashboardDesigner.CustomDataConnections Property.  

Viewing all 7205 articles
Browse latest View live


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