472,780 Members | 1,200 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

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

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 2759

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

Similar topics

7
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
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
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
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
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
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
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
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
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
by: Rina0 | last post by:
Cybersecurity engineering is a specialized field that focuses on the design, development, and implementation of systems, processes, and technologies that protect against cyber threats and...
0
linyimin
by: linyimin | last post by:
Spring Startup Analyzer generates an interactive Spring application startup report that lets you understand what contributes to the application startup time and helps to optimize it. Support for...
0
by: erikbower65 | last post by:
Here's a concise step-by-step guide for manually installing IntelliJ IDEA: 1. Download: Visit the official JetBrains website and download the IntelliJ IDEA Community or Ultimate edition based on...
0
by: kcodez | last post by:
As a H5 game development enthusiast, I recently wrote a very interesting little game - Toy Claw ((http://claw.kjeek.com/))。Here I will summarize and share the development experience here, and hope it...
0
by: Taofi | last post by:
I try to insert a new record but the error message says the number of query names and destination fields are not the same This are my field names ID, Budgeted, Actual, Status and Differences ...
14
DJRhino1175
by: DJRhino1175 | last post by:
When I run this code I get an error, its Run-time error# 424 Object required...This is my first attempt at doing something like this. I test the entire code and it worked until I added this - If...
0
by: lllomh | last post by:
Define the method first this.state = { buttonBackgroundColor: 'green', isBlinking: false, // A new status is added to identify whether the button is blinking or not } autoStart=()=>{
0
by: lllomh | last post by:
How does React native implement an English player?
2
by: DJRhino | last post by:
Was curious if anyone else was having this same issue or not.... I was just Up/Down graded to windows 11 and now my access combo boxes are not acting right. With win 10 I could start typing...

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.