Control property dymicaly assignment

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • ishrarg
    New Member
    • Oct 2008
    • 1

    Control property dymicaly assignment

    Hii all,

    Its my first thread on this forum. It seems great for solutions of programming problems.

    I have created a Method which will accept the type of control and 4 defined property of control.
    This method will create a control on the form and assign these 4 common properties on the control and it will put the created control on the form.

    Now I want one more method which will allow user to assign the property which user want to assign
    i.e.
    Code:
    SetProperty("TextBox1","ReadOnly","True")
    This method should assign readonly property to textbox1 created on the form.

    I think there is some method which allows to assign property dynamically.

    Thanks in advance
  • tlhintoq
    Recognized Expert Specialist
    • Mar 2008
    • 3532

    #2
    Originally posted by ishrarg
    Hii all,

    Its my first thread on this forum. It seems great for solutions of programming problems.

    I have created a Method which will accept the type of control and 4 defined property of control.
    This method will create a control on the form and assign these 4 common properties on the control and it will put the created control on the form.

    Now I want one more method which will allow user to assign the property which user want to assign
    i.e.
    Code:
    SetProperty("TextBox1","ReadOnly","True")
    This method should assign readonly property to textbox1 created on the form.

    I think there is some method which allows to assign property dynamically.

    Thanks in advance
    You say you have already defined a method with takes control types and properties as its arguments. But in this call you are wanting to send strings for everything. Why the switch? Seems like that is going to make life harder because you have to go searching for control by the name (not type), get the property by name, and parse the third string into a value type as well.

    This looks like it will lead down an ugly path filled with nested if statements and lots of switches.

    [CODE=c]Control[] FoundControls = Parent.Controls .Find(szPassedC ontrolName, True);
    if (FoundControls. Length>0)
    {
    // Then do a loop here to find the property
    // If the property is found then translate the text name of "True" to a boolean value of True
    // Assign it
    FoundControls[0].ReadOnly = szPassedValueSt ring.ToLower() == "true";
    }[/CODE]

    Personally, I'd look at ways to send actual controls and properties and values from the calling methods, instead of string representations of them. But that's just me.

    Comment

    Working...