c# - Why is this call not passing the information from my xml file to the winForm? -


i'm newb , i'm lost. beg patience.

i have working application believe serializing (??) xml file data using following code.

    public static string elementuser(object sender)     {         xmldocument xmldoc = new xmldocument();          //**edit:** call          //locatefolder(sender, xmldoc);         //instead of fileexistsrequest(xmldoc);          fileexistsrequest(xmldoc);          xmlnodelist nodelist = xmldoc.selectnodes("//name");          foreach (xmlnode xmlnode in nodelist)         {             if (xmlnode["user"] != null)             {                 usertxt = xmlnode["user"].innertext;                             }              else             {             }             return usertxt;         }         return usertxt;                 } 

after calling load contents of xml element in winform display user manipulate. other forms call other elements. ex math.cs call <start> <end> or <ticks> use in other dialogs.

the above designed work on 1 xml file 1 entry (??) looks this

<?xml version="1.0" encoding="utf-8"?> <submittime12>   <name key="11/18/2014">     <user>fpytel</user>     <date>11/18/2014</date>     <jobnum>00000</jobnum>     <revnum>cr8</revnum>     <task>why</task>     <start>00:00 am</start>     <end>8:00 am</end>     <ticks></ticks>     <explanation>expletives abound</explanation>   </name> </submittime12> 

it occurred me use elementuser(object sender) load other xml files same basic format, more entries. change <user> not included in reportfpytel.xml file entries user part of file name. ex:

... <name key="11/14/2014 6:45:57 am">   <date>11/3/2014</date>   <jobnum>00000</jobnum>   <revnum>00000</revnum>   <task>testing less</task>   <start>4:00 am</start>   <end>4:00 am</end>   <totaltime></totaltime> </name> <name key="11/14/2014 6:46:39 am">   <date>11/13/2014</date>   <jobnum>26356</jobnum>   <revnum>00000</revnum>   <task>red lines</task>   <start>2:00 am</start>   <end>2:00 am</end>   <totaltime></totaltime> </name> ... 

so in first code above replaced fileexistsrequest(xmldoc); following call creating in elementuser(object sender); , refactoring out of code. supplied vs2010.

    public static void locatefolder(object sender, xmldocument xmldoc)     {         string sendername = sender.tostring();         if (sendername == "start")         {          }         else if (sendername.contains("approvetime"))         {             fileexistsrequest(xmldoc);         }         else if (sendername.contains("report"))         {             fileexistsreport(xmldoc);         }         else if (sendername == "math")         {             fileexistsreport(xmldoc);         }     } 

this works without error not load elements controls on calling form. stepped through every line time called (either onload or onshown) , finds folder, finds file, finds element, assigns element string , gets ready feed string control on calling form. when take final step bring form clears string "" , shows calling form blank fields.

if put break in locatefolder(object sender, xmldocument xmldoc) function , try step past this

        string sendername = sender.tostring(); 

i nullreferenceexception error tips new keyword , checking if object null. that's error can find giving me hint. it's loading strings controls , emptying contents again. don't understand why works fine without locatefolder() call , why no error thrown when not place break in code try find error. said, have made call on shown event load event.

is there understands what's going on here. reuse code.

edit2: modified per jtmon try catch null exception. ran right past it. did have configured correctly??

    public static void locatefolder(object sender, xmldocument xmldoc)     {         //xmldocument xmldoc1 = new xmldocument();         try         {             string sendername = sender.tostring();             if (sendername == "start")             {              }             //...originalcode         }         catch         {             if (sender == null)             {                 messagebox.show("returned null");             }         }                 {             if(sender == null)             {                 messagebox.show("returned null");             }         }     } 

edit3 per galdo changed code this.

    public static void locatefolder(object sender, xmldocument xmldoc)     {         if (sender != null)         {             string sendername = sender.tostring();             if (sendername == "start")             {              }           //...originalcode         }         else         {             messagebox.show("returned null");         }     } 

my error has cleared up. both jtmon's , galdo's suggestion has cleared error, still not passing values sender form textbox.

thank commenting. i'm trying keep up. thanks!!

edit4 per request kristof. call sender of elementuser();

    private void approvetime_load(object sender, eventargs e)     {         start p = (start)this.owner;         control[] c = p.controls.find("bapprovetime", false);         button b = (button)c[0];         b.enabled = false;           widgetlogic.elementuser(this);     } 

okay, getting might solution problem.
"this" in line of code :

widgetlogic.elementuser(this); 

is class contains void approvetime_load.
i'm hoping class form.(if not please specify class)
problem code you're passing function elementuser object , later on casting string. pass string function instead of object?
assuming "this" form should :

widgetlogic.elementuser(this.text); 

you refactor elementuser , following functions not take sender object sender string(which makes bit more sense).
word sender used object because pass calling button or form.
still pass actual sender can tostring. you'd have cast sender object form , text property.


Comments

Popular posts from this blog

java - Oracle EBS .ClassNotFoundException: oracle.apps.fnd.formsClient.FormsLauncher.class ERROR -

c# - how to use buttonedit in devexpress gridcontrol -

nvd3.js - angularjs-nvd3-directives setting color in legend as well as in chart elements -