Scenario

Recently we implemented the DevExpress Notifications module into one of our projects. The functionality worked great however we wanted to improve the functionality and add our own defined fields to the notifications pop-up screen. The solution below shows how to add custom fields to predefined or hardcoded lists which cannot be added to though using the Model.

Solution

After researching the functionality we found that adding Unbound Fields to the notifications pop-up screen would be the best solution. We created a new View Controller within the Module.Win project to override the default functionality and add our own custom fields to notification listing on the pop-up screen, this view controller is shown below.

/// <summary>
/// Win Notification View Controller
/// </summary>
public partial class WinNotificationViewController : ViewController<ListView>

/// <summary> /// Initializes a new instance of the <see cref="WinNotificationViewController"/> class. /// </summary> public WinNotificationViewController()

this.InitializeComponent(); this.TypeOfView = typeof(ListView); this.TargetViewType = ViewType.ListView; this.TargetObjectType = typeof(Notification);

/// <summary> /// Called when [activated]. /// </summary> protected override void OnActivated()

base.OnActivated(); View.Editor.ControlsCreated += this.Editor_ControlsCreated;

/// <summary> /// Handles the ControlsCreated event of the Editor control. /// </summary> /// <param name="sender">The source of the event.</param> /// <param name="e">The <see cref="EventArgs"/> instance containing the event data.</param> private void Editor_ControlsCreated(object sender, EventArgs e)

GridListEditor listEditor = ((ListView)View).Editor as GridListEditor; if (listEditor != null)

GridView gridView = listEditor.GridView; gridView.CustomUnboundColumnData += new DevExpress.XtraGrid.Views.Base.CustomColumnDataEventHandler(this.GridView_CustomUnboundColumnData); GridColumn alarmTime = gridView.Columns.Add(); alarmTime.VisibleIndex = 2; alarmTime.Caption = "My Custom Field"; alarmTime.FieldName = "MyCustomField"; alarmTime.UnboundType = DevExpress.Data.UnboundColumnType.DateTime; alarmTime.DisplayFormat.FormatType = DevExpress.Utils.FormatType.DateTime;

/// <summary> /// Handles the CustomUnboundColumnData event of the gridView control. /// </summary> /// <param name="sender">The source of the event.</param> /// <param name="e">The <see cref="DevExpress.XtraGrid.Views.Base.CustomColumnDataEventArgs"/> instance containing the event data.</param> private void GridView_CustomUnboundColumnData(object sender, DevExpress.XtraGrid.Views.Base.CustomColumnDataEventArgs e)

MyNotification object = (MyNotification)((Notification)e.Row).NotificationSource; if (object != null && e.IsGetData)

switch (e.Column.FieldName)

case "MyCustomField": e.Value = object.MyCustomField; break;

The functionality above can be used to add unbound/custom fields to Grid List Editors thought out your DevExpress application.

Fill in this quick form and discover your digital future
Choose your interests:

Where to find us

We'd love to welcome you into our office! We're only 20 miles north of Peterborough, conveniently just off the A16.

Carver House
Apex Court, Elsoms Way
Pinchbeck
Lincolnshire
PE11 3UL