473,387 Members | 1,891 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,387 software developers and data experts.

Fill a combo box from collection, but bind to a custom class?

I am trying to do something a little nonstandard, and am having some
difficulty determining (a) if it can be done and (b) if so, how to do it.

What I want to do is fill a dropdown combobox with data from a collection.
Then, I want to bind that list to a member of a custom class. (Don't ask
why, just trust me on that one. <gr>).

What I'm doing now is binding the combo box to a collection, as follows:

Dim items As ArmorTypeCollection = ArmorTypeDac.Select()
With Me.ArmorType
.DataSource = items
.DisplayMember = "Value"
.ValueMember = "ID"
End With

Then, when the data is loaded onto the form, I set the default member as
follows:

Dim item As ArmorType
For Each item In ArmorType.Items
If item.ID.ToString() = _armor.Type.ID.ToString() Then
ArmorType.SelectedItem = item
Exit For
End If
Next

When the user commits her changes, I load them back into the object as
follows:

_armor.Type = ArmorTypeDac.Select().Item(Me.ArmorType.SelectedVa lue())

Is there a better way to do this? Essentially, my _armor object (of type
Armor) has a reference to an item in the armor type collection.

Any help would be greatly appreciated.
Nov 20 '05 #1
1 15015
Well the answer to your first question is yes. It can be done. If I
understand your question, you are wanting to bind a ComboBox to a data
class. I think the syntax that you are looking for is as follows:

ComboBox1.Databindings.Clear
ComboBox1.Databindings.Add ("SelectedItem", objDataClass,
"myDataClassProperty")

That's about it. I hope it helps. This is called simple databinding.
There is also complex databinding.
--

Dean
"Mike Hofer" <mi********@cox.net> wrote in message
news:bBDcb.14914$AH4.4423@lakeread06...
I am trying to do something a little nonstandard, and am having some
difficulty determining (a) if it can be done and (b) if so, how to do it.

What I want to do is fill a dropdown combobox with data from a collection.
Then, I want to bind that list to a member of a custom class. (Don't ask
why, just trust me on that one. <gr>).

What I'm doing now is binding the combo box to a collection, as follows:

Dim items As ArmorTypeCollection = ArmorTypeDac.Select()
With Me.ArmorType
.DataSource = items
.DisplayMember = "Value"
.ValueMember = "ID"
End With

Then, when the data is loaded onto the form, I set the default member as
follows:

Dim item As ArmorType
For Each item In ArmorType.Items
If item.ID.ToString() = _armor.Type.ID.ToString() Then
ArmorType.SelectedItem = item
Exit For
End If
Next

When the user commits her changes, I load them back into the object as
follows:

_armor.Type = ArmorTypeDac.Select().Item(Me.ArmorType.SelectedVa lue())

Is there a better way to do this? Essentially, my _armor object (of type
Armor) has a reference to an item in the armor type collection.

Any help would be greatly appreciated.

Nov 20 '05 #2

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

Similar topics

24
by: downwitch | last post by:
Hi, I know this has been covered here and in the .public groups, but it seems like it's been a while, especially around here, so I just thought I'd ask again to see if anyone has figured out a...
10
by: Brian | last post by:
I'm reasonably new to C#, and using a class containing a hashtable collection to feed a treeview. My problem is that I can't pull the data from the hashtable! Here's the code I have: if...
2
by: raymi | last post by:
Hi, I have a custom class that gets its properties dynamically from a database at runtime. Therefore I implemented the ICustomTypeDescriptor in this class and created a a custom...
0
by: Imar Spaanjaars | last post by:
Hi there, Can anyone tell me how to perform two-way binding with custom properties in ASP.NET 2? Let's say I have a custom class called Person that I want to bind to a FormView (using an...
3
by: Steve Franks | last post by:
Is there a way I can extend the HttpContext or one of its subclasses to include a property that exposes a custom class of mine to all ASP.NET pages? More specifically, I'd like to use a...
1
by: Marty Cruise | last post by:
I have a custom collection which contains instances of a custom class. With me so far? OK, now I set the datasource of a combobox to the collection, having overridden the ToString() function of...
1
by: Stuart Ferguson | last post by:
I am currently writing a screen in my application which uses a form view control bound to an ObjectDataSource, the Business Layer is using a custom class to overcome passing mutiple parameters to...
2
by: RafaulWolf | last post by:
I have capture data from the serial port and save it in Access database using table adapter. I defined the serial port as a class so that I can use it dynamically as it require user to add multi...
3
by: wendallsan | last post by:
Hi All, I've stumped myself writing an app that uses Prototype and a bit of PHP. Here is what I have: I have a custom class named Default_county_init_data that, upon initialization makes...
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: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

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.