c# - Define maximum for NumerictUpDown in a dictionary -


so have dictionary few controls called controldict. if want set maximum numericupdown control this:

controldict.add("amountnum" + i.tostring(), new numericupdown());             controldict["amountnum" + i.tostring()].location = new point(60, 42); controldict["amountnum" + i.tostring()].maximum = new decimal(new int[] {             -1,             -1,             -1,             0}); 

it gives me error:

'control' not contain definition 'maximum' , no extension method 'maximum' accepting first argument of type 'control' found (are missing using directive or assembly reference?)

how can solve this?

you should cast control numericupdown assign values properties:

var numeric = (numericupdown)controldict["amountnum" + i.tostring()]; numeric.maximum = 100; 

why controldict["amountnum" + i.tostring()].location works without casting?

because result control , control class has location property. , of controls including numericupdown inherited control.

items of dictionary of type control. when item dictionary using controldict["key"] result of type control. can access properties of control class. when know result control specific control type, have access specific control properties should cast specific control type.


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 -