Sparx Systems Forum
Enterprise Architect => Automation Interface, Add-Ins and Tools => Topic started by: Jeremie0 on April 24, 2014, 11:07:33 pm
-
Hello everybody,
I'm trying to delete a certain step from a scenario in c#
But nothing happens...
Here's the code
foreach (Scenario del in a.Scenarios)
{
if (del.Name == form.Text)
{
EA.Collection delsteps = del.Steps;
foreach (ScenarioStep aaa in delsteps)
{
for (short index = 0; index < delsteps.Count; index++)
{
if (aaa.Name == test)
{
MessageBox.Show(index.ToString());
delsteps.Delete(index);
}
}
aaa.Update();
delsteps.Refresh();
del.Update();
a.Refresh();
What's wrong with it ?
-
I think "aaa.Update()" will restore the step right after you deleted it.
Geert
-
Hello Geert, thanks for replying
I modified the code, but it still cannot delete the step...
foreach (object itemChecked in form.checkedListBox1.CheckedItems)
{
//MessageBox.Show(form.Text);
string test = itemChecked.ToString();
//MessageBox.Show(test);
foreach (Scenario del in a.Scenarios)
{
if (del.Name == form.Text)
{
short ind = 0;
/*
foreach (ScenarioStep aaa in del.Steps)
{
for (short index = 0; index < del.Steps.Count; index++)
{
//if (aaa.Name == test)
//{
ind = index;
//break;
// }
}
}
* */
try
{
del.Steps.DeleteAt(ind, true);
}
catch (Exception e)
{
MessageBox.Show(e.Message);
}
del.Steps.Refresh();
MessageBox.Show(del.Steps.Count.ToString());
del.Update();
a.Scenarios.Refresh();
-
Hello,
In fact, you must write :
for (short index = del.Steps.Count -1; index >=0; index--)
{
}
because you are deleting steps in the list so your list become smaller.
Solenn
-
And you don't need the refresh() and update() calls.
EA.Collection.DeleteAt() will delete immediately in the database.
You only need a refresh call if you want to do something with the Collection later on and you need it to reflect the deleted elements.
Geert
-
I have these same problem with deleting steps from scenario...
I want delete empty steps of scenario from element, but its not working, this "deleted" steps exists in this scenario.
Where is mistake in my code? :-/
foreach (EA.IDualScenario es in element.Scenarios)
{ foreach (EA.IDualScenarioStep ess in es.Steps)
{
if (ess.Name.Trim().Length == 0 &&
ess.Uses.Trim().Length == 0 &&
ess.Results.Trim().Length == 0)
{
es.Steps.Delete((short)ess.Pos);
es.Steps.Refresh();
es.Update();
element.Scenarios.Refresh();
}
}
}
Do you have any ideas? :)
-
Move the Refresh out of the loop
q.
-
Thank you for the quick response, I tried to changed my code as You suggest, but I still need help. These empty rows are not deleted, there are only moved on the end of the steps collection. I tried delate, update and refresh in different sections but still was uncorrect. Could You help me?
short esCnt = element.Scenarios.Count;
for (short esIdx = (short)(esCnt - 1); esIdx >= 0; --esIdx)
{
EA.IDualScenario es = element.Scenarios.GetAt(esIdx);
short essCnt = es.Steps.Count;
for (short essIdx = (short)(essCnt - 1); essIdx >= 0; --essIdx)
{
EA.IDualScenarioStep ess = es.Steps.GetAt(essIdx);
if (ess.Name.Trim().Length == 0 &&
ess.Uses.Trim().Length == 0 &&
ess.Results.Trim().Length == 0)
{
//1. section
es.Steps.DeleteAt(essIdx, true);
//ess.Update();
//es.Update();
//element.Update();
//es.Steps.Refresh();
//element.Scenarios.Refresh();
}
}
//2. section
//es.Update();
//es.Steps.Refresh();
//es.Update();
}
//3. section
//element.Update();
element.Scenarios.Refresh();
-
Hmm. Looks like an issue. I'm also not able to delete any step although the docu tells to use Delete(idx). I'll have some more investigation.
q.
P.S. As a possible work around you can delete the whole scenario and recreate it with the valid scenario steps. Deleting the scenario worked as desired.
P.P.S. Definitely deletion does not work for single steps. So you should a) report a bug (link bottom right) and b) use the work around above.
-
Thank you for your interest in my problem, I'm waiting for the results of your tests 8-)
-
Did you see the P.S. in my post above?
q.
-
Yes, I saw. Thank you, I'm doing as you wrote.
I was thinking that You will make other tests (?).
-
Nope. I'm almost 100% sure that this is a bug. There's always the chance that one is doing something stupidly wrong. But if two people come to the same conclusion. There's a good chance that you're the first to manipulate scenario steps. Most people were just after creating steps, not modifying or deleting them. I have also tested with 9.3 and the issue is the same there.
I'd ask you to send the bug report. I once stopped sending bug reports since I had so many open issues and no corrections (or at least very few).
q.
-
I sent the bug report. If I get an answer, I'll pass it on the forum.
Thank You for help.