c# - Read item from listbox in WPF -


i have listbox in wpf c# contains entries. out of entries, i'll update single entry. want is, when click on "done editing" button, want read updated(whose text changed) entry instead of other entries.

my entry name "harvest_timesheetentry". tried below line, reads entries.

harvest_timesheetentry h = listbox1.selecteditem harvest_timesheetentry; 

any idea?

i prefer address problem using selecteditem property of listbox or currentitem of datagrid , bind property in viewmodel.

<listbox itemssource="{binding harvesttimesheet}" selecteditem={binding currententry}.../>  <button content="done editing..." command="{binding doneeditingcommand}"/> 

in viewmodel have

    private harvest_timesheetentry _currentharvest_timesheetentry;     public harvest_timesheetentry currentharvest_timesheetentry     {         { return _currentharvest_timesheetentry; }         set         {             if (_currentharvest_timesheetentry == value) return;             _currentharvest_timesheetentry = value;             raisepropertychanged("currentharvest_timesheetentry");         }     } 

this set selected item in listbox.

my viewmodel provides code button. i'm using mvvm light provide relaycommand , raisepropertychanged.

    private relaycommand _doneeditingcommand;     public relaycommand doneeditingcommand     {         { return _doneeditingcommand ?? (_doneeditingcommand = new relaycommand(handledoneediting, () => true)); }         set { _doneeditingcommand = value; }     }      public void handledoneediting()     {         if (currentharvest_timesheetentry != null)             //do whatever need do.     } 

it's little more work control , flexibility on flow.


Comments

Popular posts from this blog

image - ClassNotFoundException when add a prebuilt apk into system.img in android -

I need to import mysql 5.1 to 5.5? -

Java, Hibernate, MySQL - store UTC date-time -