Home All Groups Group Topic Archive Search About
Author
16 Jan 2006 7:34 PM
George Hardy
hello all,

i am trying to impelement form level security in my vb.net 2003 application.
i have a database table that has the name of the form, subform, userid, and
read,edit,del,add rights (boolean).  The subform is a group box or tabpage
that would be visible or enabled (read or edit rights)

my question is:
I have a security class I pass a form object into.  When I try to set the
enabled property or visible property on the group box in question, i get a
run-time exception: "Cast from string "grpInventory" to type 'Integer' is
not valid"

Here is the code in my Security class:
MyForm.Controls(subformname).Enabled = True

So how can I access a control on a passed in form, if i cant do it by name?

Thanks a bunch!
george hardy

Author
16 Jan 2006 7:55 PM
AMDRIT
I didn't see a findcontrolbyname, or a getcontrolbyname function listed.
You could create your own though

public notinheritable class formhelperfunctions
  public shared function GetControlbyName(Contianer as Control, Name as
string) as control
    'any friend or public control will be found within this control

    for each ctrl as control in container.controls
     if string.compare(ctrl.name,name) = 0 then
      return ctrl
    end if
    next container

  end function
end class

Class Form1
  private sub TestMe
    dim objControl as control
    objControl = formhelperfunctions.getcontrolbyname(me,"Textbox1")
    if not objControl is nothing then
      ..do work here
    else
      msgbox("there was applying security, an expected control could not be
found.")
      me.customstate = customstateenum.securitycouldnotbeset
      exit sub
    end if
  end sub
End Class

Show quoteHide quote
"George Hardy" <spamlessihope-ghardy@usmedequip.com> wrote in message
news:er3H%23QtGGHA.1452@TK2MSFTNGP11.phx.gbl...
> hello all,
>
> i am trying to impelement form level security in my vb.net 2003
> application.
> i have a database table that has the name of the form, subform, userid,
> and
> read,edit,del,add rights (boolean).  The subform is a group box or tabpage
> that would be visible or enabled (read or edit rights)
>
> my question is:
> I have a security class I pass a form object into.  When I try to set the
> enabled property or visible property on the group box in question, i get a
> run-time exception: "Cast from string "grpInventory" to type 'Integer' is
> not valid"
>
> Here is the code in my Security class:
> MyForm.Controls(subformname).Enabled = True
>
> So how can I access a control on a passed in form, if i cant do it by
> name?
>
> Thanks a bunch!
> george hardy
>
>
>
Author
17 Jan 2006 3:33 PM
George Hardy
thanks!  i will give it a try.

george

Show quoteHide quote
"AMDRIT" <amd***@hotmail.com> wrote in message
news:uuVRJbtGGHA.1032@TK2MSFTNGP12.phx.gbl...
>I didn't see a findcontrolbyname, or a getcontrolbyname function listed.
>You could create your own though
>
> public notinheritable class formhelperfunctions
>  public shared function GetControlbyName(Contianer as Control, Name as
> string) as control
>    'any friend or public control will be found within this control
>
>    for each ctrl as control in container.controls
>     if string.compare(ctrl.name,name) = 0 then
>      return ctrl
>    end if
>    next container
>
>  end function
> end class
>
> Class Form1
>  private sub TestMe
>    dim objControl as control
>    objControl = formhelperfunctions.getcontrolbyname(me,"Textbox1")
>    if not objControl is nothing then
>      ..do work here
>    else
>      msgbox("there was applying security, an expected control could not be
> found.")
>      me.customstate = customstateenum.securitycouldnotbeset
>      exit sub
>    end if
>  end sub
> End Class
>
> "George Hardy" <spamlessihope-ghardy@usmedequip.com> wrote in message
> news:er3H%23QtGGHA.1452@TK2MSFTNGP11.phx.gbl...
>> hello all,
>>
>> i am trying to impelement form level security in my vb.net 2003
>> application.
>> i have a database table that has the name of the form, subform, userid,
>> and
>> read,edit,del,add rights (boolean).  The subform is a group box or
>> tabpage
>> that would be visible or enabled (read or edit rights)
>>
>> my question is:
>> I have a security class I pass a form object into.  When I try to set the
>> enabled property or visible property on the group box in question, i get
>> a
>> run-time exception: "Cast from string "grpInventory" to type 'Integer' is
>> not valid"
>>
>> Here is the code in my Security class:
>> MyForm.Controls(subformname).Enabled = True
>>
>> So how can I access a control on a passed in form, if i cant do it by
>> name?
>>
>> Thanks a bunch!
>> george hardy
>>
>>
>>
>
>