473,511 Members | 10,700 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Strange problem when doing databinding to a combo box - Please Help

URGENT HELP REQUIRED FROM GURUS

Hi,

I have a custom object that implements ICollection and IListSource. This
object has also an enumerator defined for it which implements IEnumerator
and IList. Now, I'm trying to bind object to a combo box. The bidning
happens correctly, but I'm unable to set the DisplayMember property of the
combo box (the count of items in the combo box gives me the correct value,
but no items are displayed in the combo box).

This is what I do.

My custom Class defenition

public class CustomCollection : ICollection, IListSource
{
...
...
/// <summary>
/// Returns an IList used for Data Binding
/// </summary>
/// <returns>IList</returns>
IList IListSource.GetList()
{
return(this.GetList());
}

/// <summary>
/// Returns an IList used for Data Binding
/// </summary>
/// <returns>CustomEnumerator</returns>
public CustomEnumerator GetList()
{
return(new CustomEnumerator(this, this.dataTable.DefaultView));
}

public class CustomEnumerator : IEnumerator, IList
{
...
...
}
}

This CustomCollection is a collection of customobjects (the enumerator
returns a custom object).

Now, in my windows form, I have the following code

CustomCollection custom = new CustomCollection();
custom.Fill(); // This fills the values
this.comboBox1.DataSource = custom;
this.comboBox1.DisplayMember = "Name"; //The field property of the object
that I want to be displayed
this.ComboBox1.ValueMember = "ID";

When the above code is executed, the combobox loads 10 entries (correct
value) but nothing is shown in the combobox (I guess because the DisplayName
property is not resolved correctly). How do I set the display name property
in this case? For example, if I do the following

MessageBox.Show(((customobject)comboBox1.Item[0]).Name) - gives me the value
of the Name property of the first "customobject" object in the combo box.
How do I set the DisplayName property of the combobox to this "Name"
property?
The strangest thing - if I set the Sorted property of the combo box to
"true", then the binding work fine!!! But the problem is that only the text
items are sorted and the associated value members are not sorted, so
everything gets messed up and I cannot rely on the SelectedValue property
anymore.

The same scenerio works perfectly in ASP.NET - if I bind my custom object to
a DropDownList webcontrol, and set the DataTextField property to "Name", it
works fine.

Thanks,
CGuy
Jul 19 '05 #1
0 2810

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

Similar topics

7
8485
by: Nicolae Fieraru | last post by:
Hi All, I am trying to change the rowsource of a combobox when I click on it. I played with many events, associated with the form and the combobox, but still haven't figured out what is the way...
2
1968
by: michele | last post by:
Hi, i'm using a datagrid control in my webform, with AutoGenerateColumns=false; it work very well if EnableViewState=true; including paging and sorting, but this cause a big performance issue, so...
6
2301
by: Nathan Sokalski | last post by:
I am using a DataSet as the DataSource of a DataList in my code. The SQL used to get the data from the database begins with: SELECT...
1
1379
by: amar shukla | last post by:
hi all, i have a problem, i am coding a problem, which is suppose to fetch records from database into a combobox and there after based on the selection of value it has to proceed further , i...
0
267
by: CGuy | last post by:
URGENT HELP REQUIRED FROM GURUS Hi, I have a custom object that implements ICollection and IListSource. This object has also an enumerator defined for it which implements IEnumerator and...
5
1807
by: Dennis | last post by:
I am trying to create a form using databinding to a dataset and one of the fields requires the user to select from a list of optons. Any hints on how to do this other than bind the field to a...
2
1499
by: sara | last post by:
I have a simple form with a combo box on top and then when a record is chosen the remaining 3 fields from the table on the form. My problem is that if I open the form on its own, all is fine. I...
3
1416
by: Tomasz J | last post by:
Hello Developers, I have a control derived from System.Web.UI.WebControls.WebControl. Control has this property: public string Value { set { _value = value; } get { return _value; }
2
3730
by: scdowney | last post by:
First and foremost, thank you in advance for any attempts to help me out. I am working on a project with work, and it requires I use CSS selectors to locate elements within a webpage. For the...
0
7251
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
7148
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
7367
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,...
0
7430
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...
1
7089
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...
0
5673
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,...
1
5072
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...
0
3230
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...
1
790
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.