473,549 Members | 3,099 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 CustomCollectio n : ICollection, IListSource
{
...
...
/// <summary>
/// Returns an IList used for Data Binding
/// </summary>
/// <returns>ILis t</returns>
IList IListSource.Get List()
{
return(this.Get List());
}

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

public class CustomEnumerato r : IEnumerator, IList
{
...
...
}
}

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

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

CustomCollectio n custom = new CustomCollectio n();
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 "customobje ct" 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 2821

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

Similar topics

7
8493
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 of doing it. I have a table with products, tblProducts, some of them are Active while others are Inactive. The form shows all the products...
2
1974
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 i've decided to set EnableViewState=false: now the events related to the datagrid have some strange behavours: for example the PageIndexChangedEvent...
6
2304
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 members.organization,artists.artist,artists.email,artists.website,members.email FROM members INNER JOIN artists ON members.memberid=artists.memberid WHERE Notice that both tables involved in the SELECT...
1
1382
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 have used sqldataadpter.fill(dataset) as well for the selectedvalue,
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 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...
5
1814
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 label or text box to display the current field value then add a combo box with the list of items to chose from? -- Dennis in Houston
2
1501
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 see the record I wanted and when I change the record in the drop-down, the data fields that go with that record are displayed. HOWEVER, when I...
3
1419
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
3732
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 most part, I have had no issues using the selectors, but I am having a very strange issue which does not seem to make much sense to me. Please advise if...
0
7446
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...
1
7470
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...
0
7809
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
0
6041
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...
1
5368
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...
0
5088
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3480
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
1058
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
763
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...

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.