Page 1 of 1

Suggested API improvment for working with controls on a form

PostPosted: Sun Aug 07, 2016 5:27 pm
by SBarnes
Whilst Scott gave an excellent example of adding controls to a form (viewtopic.php?f=27&t=404&p=1306&hilit=add+control#p1306)

and you can use something like

if (JiwaForm.GetType() == typeof(JiwaFinancials.Jiwa.JiwaSalesUI.SalesOrder.SalesOrderEntryForm))
{
JiwaFinancials.Jiwa.JiwaSalesUI.SalesOrder.SalesOrderEntryForm salesform = (JiwaFinancials.Jiwa.JiwaSalesUI.SalesOrder.SalesOrderEntryForm)JiwaForm;
TableLayoutPanel parentpanel = (TableLayoutPanel)(salesform.Controls.Find("TableLayoutPanel2", true)[0]);
UltraTextEditor matchdelstate = (UltraTextEditor)(salesform.Controls.Find("txtDeliveryState", true)[0]);
}

to find controls would it be possible to add to the generic maintenance form a GetControlByName("ControlName", SearchChildren) function?

And some sort of SetControlValueByName and GetControlValueByName would also be nice if possible as well.

Re: Suggested API improvment for working with controls on a  Topic is solved

PostPosted: Sun Aug 07, 2016 6:33 pm
by Mike.Sheen
Hi Stuart,

Bug 12928 has been added to address this

Mike

PS:

Also, instead of:

Code: Select all
if (JiwaForm.GetType() == typeof(JiwaFinancials.Jiwa.JiwaSalesUI.SalesOrder.SalesOrderEntryForm))


Why not use:

Code: Select all
if (JiwaForm is JiwaFinancials.Jiwa.JiwaSalesUI.SalesOrder.SalesOrderEntryForm)


I think they are equivalent - I tend to use the latter in C#, but perhaps I'm overlooking something.

Re: Suggested API improvment for working with controls on a

PostPosted: Tue Aug 09, 2016 2:29 pm
by Scott.Pearce
The .Net framework already has this:

Code: Select all
Control[] myControls = myForm.Controls.Find("MyControlName",true);

Re: Suggested API improvment for working with controls on a

PostPosted: Tue Aug 09, 2016 2:37 pm
by SBarnes
Hi Scott

Yes it does and the code I provided in the original post does that call but the problem is it assume that an array with element zero comes back every time which may not be the case I left out the error handling for simplicity what I was suggesting for a function was to cover of the error handling and probably return null/nothing if not found.