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

Databind to Custom Class

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
the custom class to return one of its text properties.
Life is good.

The first of two problems involves the combobox showing
the first item in the collection. To get around this,
I've added a dummy class with a null text property, and a
tag that equals 0. Question one: is there a better way
to have the combobox default to nothing following
databinding to my collection?

The second problem: After populating the combobox by
setting its datasource to the collection, I want to
specify the selected item (if one exists) by pointing it
to a class which has been populated on the side that is
not contained in the collection, but is identical to one
which it contains. I want to achieve:

cmbCustomers.selecteditem = myJob.Customer

Am I dreaming, or is there a way to do this without
having to implement a 'For i' loop with a lot of CType-
ing?
Nov 20 '05 #1
1 3692
Hi,

For the first problem: Right after setting your combo box's datasource to
your custom collection, set your combo box's SelectIndex to -1. Note that
this will work only for the first time I think.

For the second problem: Assuming your Customer has a unique ID (such as a
string), you can inherit your custom selection from Hashtable (or a
collection that will take a key and return the item object), then this will
work.

cmbCustomers.SelectedItem = CType(cmbCustomers.DataSource,
MyCustomCollectionType).Item(myJob.Customer.Unique ID)

Hope it helps,

Huy Nguyen, Visual Basic team.

This posting is provided "AS IS" with no warranties, and confers no rights.
Use of included script samples are subject to the terms specified at
http://www.microsoft.com/info/cpyright.htm

Note: For the benefit of the community-at-large, all responses to this
message are best directed to the newsgroup/thread from which they
originated.

Nov 20 '05 #2

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

Similar topics

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) {...
1
by: Thomas Jespersen | last post by:
Hello How do I databind a ASP.NET Texbox to a custom object. I a WinForm I do it like this: Dim myCustomerObject As Customer() Private Sub CreateNewCustomer myCustomerObject = New...
2
by: Kel Good | last post by:
Hello, I am binding a custom IList object to a DataList that I am using for a web menu. The items in the custom IList have properties that allow me to dynamically define how my menu behaves. My...
0
by: Bryce Budd | last post by:
Hi, I have a webform which has several server controls attached. The entire form is data bound to custom objects. The collection objects are cached using the Cache object. In my use case, I...
1
by: John Blair | last post by:
Hi, how do i reset a dropdownlist selectedindex value to a specific value - when the dropdownlist isa in a custom grid header, is data bound, and the main grid has been rebound to its...
0
by: Michael Fällgreen | last post by:
I'm in a jam here. I need to make my own collection of customers to simplify the inteface (don't want Add, CopyTo, Contains and so on - need a nice clean interface). I can do this by NOT inherit...
3
by: Mark Leistner | last post by:
I am having problems getting a gridview to bind to custom objects under any non-full trust level. I created a test project to verify what I am seeing isn't a side effect of other code in my...
1
by: Mark Olbert | last post by:
I have a GridView as a child control in a custom composite control which is stubornly refusing to databind at design time. I'm convinced I must be missing something about how the databinding process...
3
by: =?Utf-8?B?cm9kY2hhcg==?= | last post by:
hey all, i was working on a formview and when i pressed my custom edit button to put the formview in edit mode, i then, recursively loop thru the page controls and see all the controls such as...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
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:
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...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
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...

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.