c# - Changing the stored value in a textbox -


my winform capable of storing values entered textbox, when appropriate node selected on treeview, these values return text box entered into. however, i'm having issue in trying amend program user can on write value have stored.

this how set @ moment:

private void tagtextbox_textchanged(object sender, eventargs e) {     _screentag = tagtextbox.text;      if (_selectednode > -1)     {         node n = _nodelist[_nodelist.count - 1];         n.tag = _screentag;     } } 

the above method first stores value entered tagtextbox. next pass dictionary contains list of nodes (custom class , not confused treeview node, sorry):

foreach (keyvaluepair<string, entry> pair in n.nodedictionary) {                  if (pair.key == "tag ")     {         tagtextbox.text = (string)pair.value.value;     } } 

the above method gets called when node (not class node, tree node (sorry if thats confusing) ) on treeview selected. brings stored value , re-enters proper textbox.

now, current attempt @ trying change , update value on tag textbox associated screen:

private void tagtextbox_previewkeydown(object sender, previewkeydowneventargs e) {     // update name when enter pressed     if (e.keycode == keys.enter)     {         if (_selectednode > -1)         {             hv_screen s = _screenlist[_screenlist.count - 1];             s.tag = _screentag;         }     } } 

but doesn't work. i've checked, , method getting called not updating. know simple thing do, i'm confused here , i've spent 8 hours looking @ trying figure out how fix issue no luck.

can tell me i'm doing wrong / missing?

i'm not sure trying achieve

if (_selectednode > -1) {     node n = _nodelist[_nodelist.count - 1];     n.tag = _screentag; } 

shouldn't this:

if (_selectednode > -1)      _nodelist[_selectednode].tag = _screentag; 

this maybe it? i'm not sure though, it's hard see you're trying achieve. reason you're not using _selectednode @ all, knowing more. how set _selectednode, may impact. have misunderstood?

i re-write loop:

foreach (keyvaluepair<string, entry> pair in n.nodedictionary) {                  if (pair.key == "tag ")     {         tagtextbox.text = (string)pair.value.value;     } } 

as:

tagtextbox.text = n.nodedictionary.where(x => x.key.equals("tag")).value; 

it may have (i'm doing off top of head):

tagtextbox.text = n.nodedictionary.where(x => x.key.equals("tag")).firstordefault().value; 

i this, because me it's easier read , manipulate imho, really. obviouse advantage, reduced 7 lines 1. secondly, readability hasn't been affected. reads nicely: in nodictionary => keys == tag => first 1 list => value.


Comments

Popular posts from this blog

java - Run spring boot application error: Cannot instantiate interface org.springframework.context.ApplicationListener -

reactjs - React router and this.props.children - how to pass state to this.props.children -

Excel VBA "Microsoft Windows Common Controls 6.0 (SP6)" Location Changes -