UA Bundle SDK .NET  2.2.1.258
 All Classes Namespaces Functions Variables Enumerations Enumerator Properties Events Groups Pages
Monitored Items – Delete Monitored Items

Prerequisites

A session and a subscription with the server must be established.

Description

The following dialog shows an example dialog for deleting monitored items. Press the button “Show Code” to display the corresponding code, and the button “Help” to show this documentation page.

All currently monitored items are shown in the list at the bottom of the dialog window. Check the box in front of the items to be deleted and press the button “Delete”. Check the box in front of “Use Asynchronous Pattern” to call “BeginDelete” instead of “Delete”.

Sample Code

The following code deletes the specified monitored items.

try
{
// get the current session from the parent form.
Session session = m_parent.Session;
// nothing to do if no session.
if (session == null)
{
return;
}
// build list of items have been checked.
List<ListViewItem> items = new List<ListViewItem>();
List<MonitoredItem> monitoredItems = new List<MonitoredItem>();
foreach (ListViewItem item in MonitoredItemsLV.Items)
{
if (item.Checked)
{
MonitoredItem monitoredItem = (MonitoredItem)item.Tag;
monitoredItems.Add(monitoredItem);
items.Add(item);
}
}
// delete monitored items.
List<StatusCode> results = m_subscription.DeleteMonitoredItems(
monitoredItems,
new RequestSettings() { OperationTimeout = 10000 });
// update results in the list.
for (int ii = 0; ii < results.Count; ii++)
{
if (StatusCode.IsGood(results[ii]))
{
items[ii].Remove();
continue;
}
UpdateItem((ListViewItem)monitoredItems[ii].UserData, monitoredItems[ii]);
}
// adjust widths.
foreach (ColumnHeader header in MonitoredItemsLV.Columns)
{
header.Width = -2;
}
}
catch (Exception exception)
{
ExceptionDlg.Show(this.Text, exception);
}