private void OnAddNewTest(object sender, CommandEventArgs e)
 {
     if (Grid.SelectedRows != null && Grid.SelectedRows.Count == 1 && TestClassesInitialized)
     {
         try
         {
             InstanceState dataItem        = (InstanceState)(Grid.SelectedRows[0].Cells[0].Tag as GridDataItem).DataItem;
             Guid          currentObjectId = dataItem.PartialMonitoringObjectId;
             if (currentObjectId == Guid.Empty && dataItem.ManagedEntityId != Guid.Empty)
             {
                 currentObjectId = dataItem.ManagedEntityId;
             }
             if (currentObjectId == Guid.Empty)
             {
                 currentObjectId = dataItem.GetPartialMonitoringObject(ManagementGroup).Id;
             }
             using (NewTestDialog newTestDialog = new NewTestDialog(ManagementGroup, TestClassesAddCommands[e.Id.Guid], ManagementGroup.EntityObjects.GetObject <MonitoringObject>(currentObjectId, ObjectQueryOptions.Default), Guid.Empty))
             {
                 newTestDialog.ShowDialog();
             }
             SendRefreshCommandToDetailView();
         }
         catch (Exception ex)
         {
             MessageBox.Show($"In {System.Reflection.MethodBase.GetCurrentMethod().Name} {ex.GetType().Name} said {ex.Message} at {ex.StackTrace}");
         }
     }
 }
 private void OnEditTest(object sender, CommandEventArgs e)
 {
     if (DetailView is TestBrowser tb && tb.Grid.SelectedRows != null && tb.Grid.SelectedRows.Count == 1)
     {
         TestObjectAdapter targetTestObject = (TestObjectAdapter)tb.Grid.SelectedRows[0].DataBoundItem;
         using (NewTestDialog ntd = new NewTestDialog(ManagementGroup, null, null, targetTestObject.Source.Id))
         {
             ntd.ShowDialog();
         }
         // emulate Refresh command for detail view
         SendRefreshCommandToDetailView();
     }
 }