1

i want to create a custom control that has multiple value properties. For example the Size property of any toolbox control, it takes two parameters a width and a height.

Click here for an example

So how can i create a property of a control that will take two or more values as inputs to its Set method, or by any other method, and we can use them in a single property?

i want to create something similar to the Size property that it should take more than one arguments when i call the property of the custom control.

For example: if i create a custom control named "CustomComboBox" and then define a property named "addMovies"

now when i access this property in my code :

customComboBox.addMovies("value1", "value2", "value3")

By default if i create a property in my custom control it wold be something like this:

Private multipleMovies As String
    Public Property AddMovies() As String
        Get
            Return multipleMovies 
        End Get
        Set(ByVal value As String)
            multipleMovies = value
        End Set
    End Property

So i want to change this property such that, it takes more than one value

Affan Mirza
  • 107
  • 2
  • 10
  • just use `List(Of String)` – Mederic Apr 18 '17 at 09:53
  • List(of String) in my property? – Affan Mirza Apr 18 '17 at 09:56
  • you say AddMovies() as boolean if you check the [MSDN Boolean](https://msdn.microsoft.com/en-us/library/wts33hb3.aspx) you see it will only return **True** or **False** that's programming 101. I invite you to check the different [Data Types](https://msdn.microsoft.com/en-us/library/47zceaw7.aspx) And also how to use [List (Of T)](https://msdn.microsoft.com/en-us/library/6sh2ey19(v=vs.110).aspx) – Mederic Apr 18 '17 at 10:07
  • sorry thats my bad, i just edited the code, its "String" instead of "Boolean" – Affan Mirza Apr 18 '17 at 10:13
  • well your code works just do: `customComboBox.addmovies = {"Value 1", "Value 2", "Value 3"}` – Mederic Apr 18 '17 at 10:52
  • The `Size` properties take one (1) argument - a `Size` type. It is the `Size` type that can take two arguments in the constructor, but itself has 2 properties: `Height` and `Width`. Your `addMovies` is not a property but a method. For an actual `Movies` property define it as a Collection – Ňɏssa Pøngjǣrdenlarp Apr 18 '17 at 12:34
  • I'd think it would be better to take an `IEnumerable(Of String)` rather than `List(Of String)` for this purpose, since it would be less limiting on clients. If you have a List as the underlying container, you can use the ctor that takes an `IEnumerable` as the argument to construct or use `AddRange` to add the values. – Craig Apr 18 '17 at 14:04

0 Answers0