c# - How to add the lostfocus event handler to a dynamically created combobox's textbox? -


the combobox not editable have tried:

textbox txtbox = (textbox)mycombo.template.findname("part_editabletextbox", mycombo); 

but turns null.

i have tried adding windows xaml:

   <style targettype="{x:type combobox}">         <setter property="template">             <setter.value>                 <controltemplate targettype="{x:type textbox}">                     <border x:name="part_editabletextbox" focusable="true" background="{templatebinding background}" />                 </controltemplate>             </setter.value>         </setter>     </style> 

but system.windows.markup.xamlparseexception occurred:

set property 'system.windows.resourcedictionary.deferrablecontent' threw exception. 

here code use create combobox , set it's position in grid:

public static system.windows.controls.combobox createnewcombobox(string newcomboboxname, selectionchangedeventhandler selectionchangedeventhandler,routedeventhandler lostfocuseventhandler)     {         system.windows.controls.combobox newcombobox = new system.windows.controls.combobox();         newcombobox.name = newcomboboxname;         if (selectionchangedeventhandler != null) newcombobox.selectionchanged += selectionchangedeventhandler;         if (lostfocuseventhandler != null) newcombobox.lostfocus += lostfocuseventhandler;         return newcombobox;     }      public static void setnewcontrollocation(system.windows.controls.control control, int32 rowindex, int32 columnindex, grid parent)     {         grid.setrow(control, rowindex);         grid.setcolumn(control, columnindex);         parent.children.add(control);     } 

this add lostfocus combobox not combobox's text box.

there 1 row user selects , enters data. user can add more rows clicking plus button or left hand side of screen or using f5 key. row contains several controls 1 of combobox. comboboxes drops down list of product names requires messagebox display if products selected. if put code in selectionchanged event handler , user searching combobox messagebox show everytime pass 1 of products requires it. if put code messagebox in combobox's lostfocus event handler fires when click on combobox's textbox , when close window. need find way attach event handler combobox's textbox.

if there way of going let please let me know.

screen shot


Comments

Popular posts from this blog

c# - DetailsView in ASP.Net - How to add another column on the side/add a control in each row? -

javascript - firefox memory leak -

Trying to import CSV file to a SQL Server database using asp.net and c# - can't find what I'm missing -