Click here to Skip to main content
15,884,298 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
How can I stop the value from resetting it self when I perform the operation. if you can help than thank you in advance.

What I have tried:

C#
public void ParseXML()
        {
            if (File.Exists(userPermissionLoc))
            {
                XDocument doc = XDocument.Load(userPermissionLoc);
                var elements = doc.Root.Elements("Roles").ToList();
                foreach (var x in elements)
                {
                    //Console.WriteLine("Roles :: " + x.Value);
                    var UIControls = listControls.Where(y => y.userRole == x.Value).ToList();
                    var roles = doc.Root.Elements(x.Value.Replace(" ", "_")).Where(y => y.Name == x.Value.Replace(" ", "_"));
                    var permissions = roles.Elements("Permissions");
                    var permission_value = permissions.Elements("Permission").ToList();
                    var visible_value = permissions.Elements("Visible").ToList();
                    var enable_value = permissions.Elements("Enabled").ToList();
                    for (int i = 0; i < permissions.Count(); i++)
                    {
                        if (permissions.Count() == UIControls.Count)
                        {
                            UIControls[i].isVisibled.IsChecked = Convert.ToBoolean(visible_value[i].Value);
                            UIControls[i].isEnabled.IsChecked = Convert.ToBoolean(enable_value[i].Value);
                        }
                    }
                }
            }
        }
Posted
Updated 4-Mar-21 19:52pm
v2
Comments
BillWoodruff 5-Mar-21 2:24am    
We can't read your mind: which variable, where ?

1 solution

We can't tell, partly because we have no idea what you mean by "stop resetting the value" as we have no idea what value is being "reset" or how you can even tell!
But mostly because we have no access to your data file, so even if we wanted to, we couldn't run your code to find out what might be going on, and what of that you might consider to be an error ...

So, it's going to be up to you.
Fortunately, you have a tool available to you which will help you find out what is going on: the debugger. If you don't know how to use it then a quick Google for "Visual Studio debugger" should give you the info you need.

Put a breakpoint on the first line in the function, and run your code through the debugger. Then look at your code, and at your data and work out what should happen manually. Then single step each line checking that what you expected to happen is exactly what did. When it isn't, that's when you have a problem, and you can back-track (or run it again and look more closely) to find out why.

Sorry, but we can't do that for you - time for you to learn a new (and very, very useful) skill: debugging!
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900