Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1375
  • Last Modified:

Coding User Control VB 2008

I am creating a user control that has a split container and several FPSpread grids on it.
I thought I would create a user control so that I could dynamically add the control to a new tab when a user clicks a button.
I have all the controls settings the way I want.  
Now I need to know if I can actually code this usercontrol to handle all the database insert/update/delete etc. procedures.
First, can I add the main code and class to this control?
Second, are there any problems I should know about if I do?
Third, If there are no problems associated with adding the code, would I do it just like I do when usings a windows form app?
Thanks
0
Sheritlw
Asked:
Sheritlw
  • 2
1 Solution
 
Hawkvalley1Commented:




If you set up the insert/update/delete statements in there own sub routines then yes, when you are creating the UC use the addHandler statement to point to a sub routine that will activate the insert/update/delete sub routines and you can even pass values to the sql-subs.
Something like:
'code in the button click that creates the UC
***
Dim uc As New <yourUserControl>
With uc
addHandler .MyRaisedClickEvent, AddressOf MyUCClickEvent
'add more stuff as needed access properties directly here
End With
***
'then you make the Sub named MyUCClickEvent in the main form
***
Private Sub MyUCClickEvent(<same signature as the Public Event signature on the UC>)
  MyInsertSub(combobox1.selecteditem) 'say this combobox holds the tables you are using End Sub  
Private Sub MyInsertSub(ByVal table As String)
'in your insert statement
Dim sql As String = " INSERT INTO " & table & " (your fields)......
End Sub
***
In the UC make a Public Event named 'MyRaisedClickEvent(ByVal something as <whatever data type>)' , then in the click event for the button use
RaiseEvent MyRaiseClickEvent(<any variables that you need to pass from the UC>) to the main form.
This is just an example of passing events thru your UC's much customizing can be added.
I see your code will need to more elabrate poss passing several values and you will have to be clever in the setup of each UC do draw out the right info, but it should be designable.
0
 
Hawkvalley1Commented:
Also in the MyRaisedClickEvent you have access to the values you passed from the UC's button click event. The variableName in the signature is holding the value.
0

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now