 |
hitech_huzefa Level: Scholar
 Registered: 23-06-2005 Posts: 40
|
ActiveX
Hi! i am back again.
These days i was busy working on a ActiveX control (TEXT BOX) which has many new features but i dont know how to put DataField DataSource and DataFormat on the control please help.
|
|
20-08-2005 at 04:38 AM |
|
|
misterxed Level: VB Lord

 Registered: 12-06-2005 Posts: 151
|
Re: ActiveX
Hi,
Is it that u want to ask how do u add properties to a User control, or do u want to add specifically DATAFIELD, DATASOURCE etc? If ur answer is the former one, heres the code:
'General Section:
Private m_DataField as String
'When the user asks for the property, the following code is run:
Public Property Get DataField() As String
DataField = m_DataField
End Property
'When s/he sets the property, following code is run:
Public Property Let DataField(ByVal NewValue As String)
m_DataField = NewValue
End Property
'Initialization of the control...
Private Sub UserControl_InitProperties()
m_DataField = ""
End Sub
'Whenever the control is destroyed:
'Note that control is destroyed, even when u switch from Design mode to Run mode (i.e. when u press F5)
Private Sub UserControl_WriteProperties(PropBag As PropertyBag)
PropBag.WriteProperty "DataField", m_DataField, ""
End Sub
'Whenever control is created...
Private Sub UserControl_ReadProperties(PropBag As PropertyBag)
DataField = PropBag.ReadProperty("DataField", "")
End Sub
|
Note that initialization takes place only ONCE, when a control is created. If more instances r created, they only READPROPERTIES and donot INITIALIZE...
Now that i've given a simple idea of what u're supposed to do, i'll get into little specifics for DataField:
Firstly, u'll have to determine if the control is being created in design mode or Run Mode. For this, u can use the
UserControl.Ambient.UserMode
property. Then u can add the code for the DataField property... Something like this:
Public Property Let DataField(ByVal NewValue As String)
m_DataField = NewValue
If UserControl.Ambient.UserMode Then
'Add code here to do whatever DATAFIELD property does
End If
End Property
|
____________________________
lOsT...
|
|
23-08-2005 at 02:51 AM |
|
|
hitech_huzefa Level: Scholar
 Registered: 23-06-2005 Posts: 40
|
Re: ActiveX
why the default property of a TextBox is not showing when i put the ActiveX control on the form as a DataField, DataSource,DataFormat. i was going through a activeX control i saw the above property was availab but when i created a TextBox ActiveX control the Properties was gone why and how please help.
|
|
23-08-2005 at 05:29 AM |
|
|
misterxed Level: VB Lord

 Registered: 12-06-2005 Posts: 151
|
Re: ActiveX
I think i got ur point:
U added a Textbox to ur own control, then u added this control to a Form, to check ur control... And u're not getting the DataField property in ur control... RIGHT?
Well, once u've added any other control to the USERCONTROL (that's what i will call ur control) that control becomes a part of ur control, but its properties are not automatically transferred to ur control.. for that, heres a sample:
Add a text box in USERCONTROL then,
'General Section:
Private m_DataField As String
'When the user asks for the property, the following code is run:
Public Property Get DataField() As String
DataField = m_DataField
End Property
'When s/he sets the property, following code is run:
Public Property Let DataField(ByVal NewValue As String)
m_DataField = NewValue
Text1.DataField = m_DataField
End Property
'Initialization of the control...
Private Sub UserControl_InitProperties()
m_DataField = ""
End Sub
'Whenever the control is destroyed:
'Note that control is destroyed, even when u switch from Design mode to Run mode (i.e. when u press F5)
Private Sub UserControl_WriteProperties(PropBag As PropertyBag)
PropBag.WriteProperty "DataField", m_DataField, ""
End Sub
'Whenever control is created...
Private Sub UserControl_ReadProperties(PropBag As PropertyBag)
DataField = PropBag.ReadProperty("DataField", "")
End Sub
|
This way u can add all other properties of textbox into ur USERCONTROL...
[Edited by misterxed on 24-08-2005 at 12:36 AM GMT]
____________________________
lOsT...
|
|
23-08-2005 at 07:23 PM |
|
|
hitech_huzefa Level: Scholar
 Registered: 23-06-2005 Posts: 40
|
Re: ActiveX
i did successfully DataFeld but how to do DataSource?
if it is possible can u make a little textbox activex control with DataFiled, DataSource and DataFormat properties and send it to me on shuzefa@rediffmail.com or upload on this site so that others can also see.Please
|
|
25-08-2005 at 04:49 AM |
|
|
|
|
 |
 |