I am having some problems with the NVLs I am retrieving a list of employees to be assigned to Project. While assigning the users I want to remove users that have already been added to the project.
So i included a Remove method to the NVL object but its giving an stackoverflow exception. I am not sure how to resolve this issue. I have included the code below .
Code added to the NVL object
public void Remove(int key){
if (ContainsKey(key)){
this.Remove(key);}
}
Code in the Form displaying the Users. _usrlst is the child object of the Project that contains the list of users already assigned.
foreach (User usr in _usrlst){
_users.Remove(rm.UserID);
}
I would appreciate any help in resolving this issue.
Thanks
I would have to see your entire class to have a hope of telling you exactly where it went wrong.
However, if I remember correctly on the RoleList sample class, the class maintains a static copy of the list to avoid hitting the database over and over again. It's possible that another object already removed the key you think is there, if you implemented your class in a similar manner.
Thanks for responding David.
>>It's possible that another object already removed the key you think is there
In order to make sure that an exception is not thrown, I check to see if the object contains the key before attempting to remove it.
I am not sure why I am getting stackoverflow exception though. seems totally unrelated.
thanks
public void Remove(int key)
{
if (ContainsKey(key))
{
this.Remove(key); // <--- This is calling the same function that started the whole thing.
}
}
Thanks Andres. That was pretty dumb of me.
Finally got it to work with the code below. Might not be most efficient but does the job.
public void Remove(int key,string value){
foreach (NameValuePair item in this){
if (item.Key == key && item.Value == value){
IsReadOnly =
false; this.Remove(item);IsReadOnly =
true; return;}
}
}
Copyright (c) Marimer LLC