473,385 Members | 1,867 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

How to create a "DataSource" & "Items" properties on Custom Combob

I am creating a user control containing a combobox using VB.NET(2003)
I want to add 2 public properties "DataSource" and "Items" like the
"System.Windows.Forms.ComboBox"

here is my code, but it doesn't work. What's wrong with it?

Public Property cboDataSource() As Object
Get
Return Me.cbo.DataSource 'cbo is my combobox
End Get
Set(ByVal Value As Object)
Me.cbo.DataSource = Value
End Set
End Property

Public Property cboItems() As System.Windows.Forms.ComboBox.ObjectCollection
Get
Return Me.cbo.Items
End Get
Set(ByVal Value As System.Windows.Forms.ComboBox.ObjectCollection)
Me.cbo.Items.Add(Value)
End Set
End Property
Jan 17 '06 #1
5 6886
VB Newbie wrote:
I am creating a user control containing a combobox using VB.NET(2003)
I want to add 2 public properties "DataSource" and "Items" like the
"System.Windows.Forms.ComboBox"

here is my code, but it doesn't work. What's wrong with it?

Public Property cboDataSource() As Object
Get
Return Me.cbo.DataSource 'cbo is my combobox
End Get
Set(ByVal Value As Object)
Me.cbo.DataSource = Value
End Set
End Property

Public Property cboItems() As System.Windows.Forms.ComboBox.ObjectCollection
Get
Return Me.cbo.Items
End Get
Set(ByVal Value As System.Windows.Forms.ComboBox.ObjectCollection)
Me.cbo.Items.Add(Value)
End Set
End Property


Why is the problem you are having with it?
-First problem I see is that you are mixing ideas here. You are trying
to add an ObjectCollection to the collection. You should be additem the
item. Let's say you were using strings (you could use object also, or
datarow if your datasource is a datatable)

Public Property cboItems(Index as integer) As String
Get
Return Me.cbo.Items(Index).toString
End Get
Set(ByVal Value As String)
Me.cbo.Items.Add(Value)
End Set
End Property

Hope it helps
Jan 17 '06 #2
After applying your code, I can't view the "cboitem" property in VS.NET
designer view. How can I edit the "cboitem" and "cboDatasource" property in
designer view like "System.Windows.Forms.ComboBox"'s one?

"Chris" wrote:

Why is the problem you are having with it?

-First problem I see is that you are mixing ideas here. You are trying
to add an ObjectCollection to the collection. You should be additem the
item. Let's say you were using strings (you could use object also, or
datarow if your datasource is a datatable)

Public Property cboItems(Index as integer) As String
Get
Return Me.cbo.Items(Index).toString
End Get
Set(ByVal Value As String)
Me.cbo.Items.Add(Value)
End Set
End Property

Hope it helps

Jan 18 '06 #3
VB Newbie,

Would it be not more advisable first to use the normal combobox in a bounded
and not bounded way. From your sample and question, is it clear for me that
you have not yet everything clear for yourself about the combobox.

However feel free to go on this way.

Cor
Jan 18 '06 #4
How can I move on this way?
would you mind give me some hints?

"Cor Ligthert [MVP]" wrote:
VB Newbie,

Would it be not more advisable first to use the normal combobox in a bounded
and not bounded way. From your sample and question, is it clear for me that
you have not yet everything clear for yourself about the combobox.

However feel free to go on this way.

Cor

Jan 22 '06 #5
VB Newbie,
How can I move on this way?
would you mind give me some hints?

I have searched on MSDN, i found this page maybe is it something for you.

http://msdn2.microsoft.com/en-us/library/k0e26a9k.aspx

I hope this helps,

Cor
Jan 23 '06 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Scott McNair | last post by:
Hi all, Forgive me in advance for any noobish questions I may ask... although I'm well-versed in classic ASP/VB, I'm still learning some of the deeper nuances of .NET, particularly some of the...
3
by: charliewest | last post by:
I have binded a dropdownlist control to a data view. I am trying to add a listitem to this already binded control, however, i cannot figure this out. My code is: // code to create data view...
0
by: Alistair Lacy | last post by:
Hi Ive got a custom collection of class which I use as the data source for a DataGrid control. I execute the following code prior to beginning my data binding: if (list_ is BatchWorkItem) {...
3
by: Giovanni Bassi | last post by:
Hello All, I have a class implementing IList and a global object of this class type. I have two different form objects. One has a ListBox and the other has ComboBox. Both of their datasources...
2
by: Prabhudhas Peter | last post by:
I need a ComboBox property like "ItemData" in VB.Net as in VB 6.0. The Idea behind this question is, i've created a user control combo box in vb.net with my own set of properties..now i want to...
11
by: Ron L | last post by:
I have a data table that lists a series of items in my database. In my user form, I want the user to be able to filter by a number of criteria (e.g. location, contract, date modified, etc). Other...
0
by: VB Newbie | last post by:
I am creating a user control containing a combobox using VB.NET(2003) I want to add 2 public properties "DataSource" and "Items" like the "System.Windows.Forms.ComboBox" here is my code, but it...
4
by: chaz | last post by:
here is the html : <br> <table width="100%" border="0" cellspacing="0" cellpadding="0"> <tr> <td width="<%=LABEL_WIDTH%>" class="formtext"><%= HTEXT("Connection type:")%></td> <td...
5
by: Cirene | last post by:
I seem to remember seeing a solution where a databound dropdownlist (used as a FILTER for a gridview) had the 1st item as "ALL ITEMS". It used a query with a UNION. But I can't find the example....
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.