Using Objects in UserControls
Is there any way to let the user interact with an object in it?
Printable View
Using Objects in UserControls
Is there any way to let the user interact with an object in it?
Could you explain a little more?
You can allow access to private objects through a property if that is what you mean...
VB Code:
Public Property Get SomeObject() As SomeObject Set SomeObject = mSomeObject End Property
I mean something like this:
VB Code:
Public Function TV() As TreeView Set TV = TreeView End Function
I don't know if it works the same way with functions vs properties, I would use a property. It should allow that.
:)
I'd tried your code as well... but didn't work.
What happens? Can you supply the code?
All you have to do is create an instance of the object in your class and return a ref to the calling code. I would use a property get.
---------------------------
Microsoft Visual Basic
---------------------------
Compile error:
Private object modules cannot be used in public object modules as parameters or return types for public procedures, as public data members, or as fields of public user defined types
---------------------------
Aceptar Ayuda
---------------------------
How would you do that?Quote:
Originally posted by Lethal
All you have to do is create an instance of the object in your class and return a ref to the calling code. I would use a property get.
Are you using an actual Treeview, or something of your own? If its your own class, then set the Instancing property to 5 MultiUse and it should work.Quote:
Originally posted by Mc Brain
---------------------------
Microsoft Visual Basic
---------------------------
Compile error:
Private object modules cannot be used in public object modules as parameters or return types for public procedures, as public data members, or as fields of public user defined types
---------------------------
Aceptar Ayuda
---------------------------
I'm using a TreeView, and would like to let the user access their methods and properties without any coding.
Here's an example:
Code:Option Explicit
Public Name As String
Public Property Get Clone() As MyObject
Dim clsClone As New MyObject
clsClone.Name = Me.Name
Set Clone = clsClone
End Property
I don't think that would let me do what I'm after....
Well, then its a bit tricky, you'll need to make the property type an Object, then to get the intellisense and all that, you can set a treeview variable to the propertyQuote:
Originally posted by Mc Brain
I'm using a TreeView, and would like to let the user access their methods and properties without any coding.
VB Code:
'In the Usercontrol Public Property Get TV() As Object Set TV = Treeview1 End Property 'On a form Private Sub Command1_Click() Dim tvw as Treeeview 'Only need for intellisense purposes Set tvw = Usercontrol1.TV Call tvw.Nodes.Add (Text:="Hello") End Sub
:)
For a treeview, swap out the textbox code:
Code:Option Explicit
Private myBox As TextBox
Public Property Let MyTextBox(txtExample As TextBox)
Set myBox = txtExample
End Property
Public Property Get MyTextBox() As TextBox
Set MyTextBox = myBox
End Property
Damned!! I was trying to avoid that! I mean, it won't be that intuitive for the UserControl's user.
Am I not following you? I don't think that code would work. The TreeView is on the UserControl. I would like to let the user Interact with it.Quote:
Originally posted by Lethal
For a treeview, swap out the textbox code:
Code:Option Explicit
Private myBox As TextBox
Public Property Let MyTextBox(txtExample As TextBox)
Set myBox = txtExample
End Property
Public Property Get MyTextBox() As TextBox
Set MyTextBox = myBox
End Property
Ah..got ya...i read the question 2 quick...then, you are left with the code crypt provided or just expose methods through your code that automate what you want to provide for the user.
This is what I'm after... I want the user to be able to load and remove items as if he/she had a TreeView on his/her form.
Sorry... I've uploaded the file again because the first one didn't work.
Ok... here's the version with all the "View" (ViewTree, ViewAddress, ViewWebStyle) properties coded. I guess I should have told (just in case) that the MS Windows Common Controls have to be loaded.