How to customer usercontrol

isawa

Active member
Joined
Oct 3, 2005
Messages
25
Programming Experience
Beginner
I'm created my usercontrol that have one control Label and then i'm use my control in my form but i'm con't to use property about my control how i can. vb.net 2005

thanks.
 
For instance:
VB.NET:
[COLOR=black][FONT=Courier New]<Description([COLOR=maroon]"Occurs when Button Two is clicked"[/COLOR]), _
Category([COLOR=maroon]"Action"[/COLOR])> _
[COLOR=blue]Public[/COLOR] [COLOR=blue]Event[/COLOR] ButtonTwoClick [COLOR=blue]As[/COLOR] EventHandler
 
[COLOR=blue]Protected[/COLOR] [COLOR=blue]Overridable[/COLOR] [COLOR=blue]Sub[/COLOR] OnButtonTwoClick([COLOR=blue]ByVal[/COLOR] sender [COLOR=blue]As[/COLOR] [COLOR=blue]Object[/COLOR], [COLOR=blue]ByVal[/COLOR] e [COLOR=blue]As[/COLOR] EventArgs) _
[COLOR=blue]Handles[/COLOR] ButtonTwo.Click
    [COLOR=blue]RaiseEvent[/COLOR] ButtonTwoClick([COLOR=blue]Me[/COLOR], EventArgs.Empty)
[COLOR=blue]End[/COLOR] [COLOR=blue]Sub[/COLOR]
[/FONT][/COLOR]
 
jmcilhinney said:
I think it would be better to just use the property of the UserControl as a pass-through for the ComboBox property ...
Just curious: did you actually try this? :)
It was my first approach too. But it does not seem to work as expected in design time.
 
Don Delegate said:
Just curious: did you actually try this? :)
It was my first approach too. But it does not seem to work as expected in design time.
Can't say that I did. There;d have to be a way to make it work, wouldn't there? I'm too lazy to try though. ;)
 
I think I more or less worked it out. :)
Only, the thing is: it's just Strings() all over again. Although consistent with the behaviour of ComboBox.Items and other ListControl.Items in design time.

This seems to do the trick (both the EditorAttribute and the DesignerSerializationVisibilityAttribute are needed):

VB.NET:
[SIZE=2]<Description([/SIZE][SIZE=2][COLOR=#800000]"The items of the Combobox in this User Control"[/COLOR][/SIZE][SIZE=2]), _
Editor([/SIZE][SIZE=2][COLOR=#800000]"System.Windows.Forms.Design.ListControlStringCollectionEditor, System.Design"[/COLOR][/SIZE][SIZE=2], _
[/SIZE][SIZE=2][COLOR=#0000ff]GetType[/COLOR][/SIZE][SIZE=2](UITypeEditor)), _
DesignerSerializationVisibility(DesignerSerializationVisibility.Content), _
Category([/SIZE][SIZE=2][COLOR=#800000]"Data"[/COLOR][/SIZE][SIZE=2])> _
[/SIZE][SIZE=2][COLOR=#0000ff]Public [/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]ReadOnly [/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]Property[/COLOR][/SIZE][SIZE=2] Items() [/SIZE][SIZE=2][COLOR=#0000ff]As[/COLOR][/SIZE][SIZE=2] ComboBox.ObjectCollection
[/SIZE][SIZE=2][COLOR=#0000ff]Get
[/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]    Return[/COLOR][/SIZE][SIZE=2] ComboBoxItems.Items
[/SIZE][SIZE=2][COLOR=#0000ff]End [/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]Get
[/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]End [/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]Property
[/COLOR][/SIZE]
 
Thanks everyone, my problem it's OK. :)

This code: Don't work.
Public ReadOnly Property items() As ComboBox.ObjectCollection
Get
Return Me.ComboBox1.Items
End Get
End Property

This code: so work.
Public Property Items() As String()
Get
Dim result(ComboBoxItems.Items.Count - 1) As String
ComboBoxItems.Items.CopyTo(result, 0)
Return result
End Get
Set(ByVal value As String())
ComboBoxItems.Items.Clear()
ComboBoxItems.Items.AddRange(value)
End Set
End Property
 
vb.net 2005 error "name DesignerSerializationVisibility is not declared"

my code vb.net 2005:
<System.ComponentModel.Description("The items of the Combobox in this User Control"), _
System.ComponentModel.Editor("System.Windows.Forms.Design.ListControlStringCollectionEditor, _
System.Design", GetType(Drawing.Design.UITypeEditor)), _
System.ComponentModel.DesignerSerializationVisibility(DesignerSerializationVisibility.Content), System.ComponentModel.Category("Data")> _
Public ReadOnly Property Items() As ComboBox.ObjectCollection
Get
Return ComboBox1.Items
End Get
End Property


 
I want to create Property BindingNavigator

I want to create Property about BindingNavigator for user. So user can add Control to my BindingNavigator. How to? That code don't work help me.

<System.ComponentModel.Description(
"The items of the Combobox in this User Control"), System.ComponentModel.Editor("System.Windows.Forms.Design.ListControlStringCollectionEditor, System.Design", GetType(Drawing.Design.UITypeEditor)), System.ComponentModel.DesignerSerializationVisibility(DesignerSerializationVisibility.Content), System.ComponentModel.Category("Data")> Public ReadOnly Property Itemsa() As BindingNavigator.ControlCollection
Get
Return Me.BindingNavigator_BnavButton.Items
End Get
End Property

:eek:
 
You can expose the DataSource and DisplayItem properties of the internal ComboBox from your usercontrol (and eventually place them in their own category on the toolbox).
 
How to update dataset to table? I used that code in dataset it's ok, but in database can't update why? :eek:

Try
Me.Validate()
Me.CustomerBindingSource.EndEdit()
Me.CustomerTableAdapter.Update(Me.XtremeDataSet.Customer)
MsgBox(
"Update successful")
Catch ex As Exception
MsgBox(
"Update failed")
EndTry
 
Show the text of the exception. Then you'll probably know why.
Also: how is this related to this thread?
VB.NET:
[COLOR=black][FONT=Courier New][COLOR=blue]Try[/COLOR]
    Validate()
    CustomerBindingSource.EndEdit()
    CustomerTableAdapter.Update(XtremeDataSet.Customer)
[COLOR=blue]Catch[/COLOR] ex [COLOR=blue]As[/COLOR] Exception
    MessageBox.Show(ex.ToString)
[COLOR=blue]End[/COLOR] [COLOR=blue]Try[/COLOR]
[/FONT][/COLOR]

 
isawa said:
How to get currentrow for datagridview? show some code for me.

Thanks
Please keep each thread to a single topic. This thread is already long enough. If you want to ask questions related to the original topic then use the same thread but if you have unrelated questions, as this is, please start a new thread. It makes the forum easier to use for everyone.
 
Back
Top