473,769 Members | 3,102 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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.se lecteditem = 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 3706
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.Se lectedItem = CType(cmbCustom ers.DataSource,
MyCustomCollect ionType).Item(m yJob.Customer.U niqueID)

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
1057
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) { ....} // do stuff This evaluates to true.
1
1898
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 Customer() myCustomerObject.FirstName = "Thomas"
2
3950
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 binding syntax is standard: Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load MenuItems.DataSource = GetMyCustomIList MenuItems.DataBind()
0
1157
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 have to update my database, synchronize my cached collection and refresh my UI. After my database update I call dropdownlist1.databind() and my items are exactly the same when they should be less 1 item. If I understand the "control execution...
1
1129
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 datasource? As i understand it when grid.databind is called the databind of all child controls will be called. Now i am wondering how can i post process the dropdownlist after the databind has happened.
0
1166
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 from Collections.ObjectModel.Collection(Of Customer) and do this instead: Public Class Customers Private lst As New Collections.Generic.List(Of Customer) End Class And then add my own methods (private Add, Public Count and so on) to work
3
2028
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 project and I get the same errors there: Exception Details: System.Security.SecurityException: That assembly does not allow partially trusted callers.
1
4128
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 works differently at design time. Here is the code that constructs the GridView in CreateChildControls(): gridSearch = new GridView(); gridSearch.AutoGenerateColumns = true; CommandField cmdField = new CommandField();
3
1505
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 textboxes and other input controls. well, when i press my custom New button to put the formview in insert mode (using FormView1.ChangeMode(FormViewMode.Insert) i see on the screen the input controls as normal, but when i loop thru the page...
0
9589
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9423
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10222
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
9999
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8876
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7413
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5310
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
2
3570
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2815
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.