473,569 Members | 2,765 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

comboBox displays bound data out of order

i've got a dataSet that looks like the following:

<tblTasks>

<id>0</id>

<summary>-- Select A Task--</summary>

</tblTasks>

<tblTasks>

<id>713</id>

<summary>resear ch</summary>

</tblTasks>

<tblTasks>

<id>717</id>

<summary>Othe r - time estimation</summary>

</tblTasks>

i've bound the dataSet to my comboBox as follows:

cboTasks.DataSo urce = null;

cboTasks.Items. Clear();

cboTasks.DataSo urce = oDataSet;

cboTasks.Displa yMember = "tblTasks.summa ry";

cboTasks.ValueM ember = "tblTasks.i d";

but the "-- Select Task --" option is showin up last. any idea why or how to
fix?
Nov 17 '05 #1
2 1533
Hi Dica,

you can set the DefaultView of your DataTable
as DataSource and set the Sort property of the
DefaultView to ascending. You should also set
your id column as primary key. Otherwise it could
be that the sorting won't work.

.....DataSource = oDataSet.Tables["tblTasks"].DefaultView.So rt =
"ascending" ;

Cheers
Lars Behrmann

_______________ __
Nothing is impossible. UML is the key for all your problems.
AODL - Make your .net apps OpenOffice ready
http://aodl.sourceforge.net/

Dica schrieb:
i've got a dataSet that looks like the following:

<tblTasks>

<id>0</id>

<summary>-- Select A Task--</summary>

</tblTasks>

<tblTasks>

<id>713</id>

<summary>resear ch</summary>

</tblTasks>

<tblTasks>

<id>717</id>

<summary>Othe r - time estimation</summary>

</tblTasks>

i've bound the dataSet to my comboBox as follows:

cboTasks.DataSo urce = null;

cboTasks.Items. Clear();

cboTasks.DataSo urce = oDataSet;

cboTasks.Displa yMember = "tblTasks.summa ry";

cboTasks.ValueM ember = "tblTasks.i d";

but the "-- Select Task --" option is showin up last. any idea why or how to
fix?


Nov 17 '05 #2

"Lars Behrmann" <la***********@ web.de> wrote in message
news:11******** **************@ z14g2000cwz.goo glegroups.com.. .
Hi Dica,

you can set the DefaultView of your DataTable
as DataSource and set the Sort property of the
DefaultView to ascending. You should also set
your id column as primary key. Otherwise it could
be that the sorting won't work.

....DataSource = oDataSet.Tables["tblTasks"].DefaultView.So rt =
"ascending" ;
thanks lars.
i've revised the code as per your instrucitons:
cboTasks.DataSo urce = oDataSet.Tables["tblTasks"].DefaultView.So rt = "id";
cboTasks.Displa yMember = "summary";

cboTasks.ValueM ember = "id";

but i'm getting an error:
Complex DataBinding accepts as a data source either an IList or an
IListSource

the other option i've found is to use a select statement againts the dataSet
table:

DataRow[] drarray;

drarray = oDataSet.Tables["tblTasks"].Select(null, "id",
System.Data.Dat aViewRowState.C urrentRows);

for (int i=0; i < drarray.Length; i++)

{

cboTasks.Items. Add(drarray[i]["summary"].ToString());

}

this option seems to work fine, but i can't find any way to add the
valueMember (the ID column from my dataSet) to the comboBox this way.

any other ideas?

tks


Cheers
Lars Behrmann

_______________ __
Nothing is impossible. UML is the key for all your problems.
AODL - Make your .net apps OpenOffice ready
http://aodl.sourceforge.net/

Dica schrieb:
i've got a dataSet that looks like the following:

<tblTasks>

<id>0</id>

<summary>-- Select A Task--</summary>

</tblTasks>

<tblTasks>

<id>713</id>

<summary>resear ch</summary>

</tblTasks>

<tblTasks>

<id>717</id>

<summary>Othe r - time estimation</summary>

</tblTasks>

i've bound the dataSet to my comboBox as follows:

cboTasks.DataSo urce = null;

cboTasks.Items. Clear();

cboTasks.DataSo urce = oDataSet;

cboTasks.Displa yMember = "tblTasks.summa ry";

cboTasks.ValueM ember = "tblTasks.i d";

but the "-- Select Task --" option is showin up last. any idea why or how to fix?

Nov 17 '05 #3

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

Similar topics

2
3427
by: Phil | last post by:
My form uses a dataset containing two tables, a base table (Contact) and a lookup table (Insurer). My combobox is bound as follows: DataSource = datasetContact DisplayMember = Insurer.InsurerName ValueMember = Insurer.InsurerId DataBindings.SelectedValue = Contact.InsurerId It generally works fine. I am able to navigate records and
2
2501
by: Susan Bricker | last post by:
Greetings! Still the same application (as previous posts). I worked on the app while at work (don't tell my boss ... cause this is just for fun and not work related) and the form was working, but now when I try to repeat the code at home (for real) it won't work. I suspect that I haven't replicated the logic and forms at home from what I...
0
1905
by: Susan Bricker | last post by:
The following error: "The current field must match the join key '?' in the table that seves as t the 'one' side of one-to-many relationship. Enter a record in the 'one' side table with the desired key value, and then make the entry with the desired join key in the 'many-only' table." ... happens when I click on an entry of a combobox. ...
2
1798
by: Susan Bricker | last post by:
I went back to read my post and found an error in my description ... here is the post, again, corrected: The following error: "The current field must match the join key '?' in the table that seves as t the 'one' side of one-to-many relationship. Enter a record in the 'one' side table with the desired key value, and then make the entry...
6
1773
by: Doug Bell | last post by:
Hi I have a datagrid with a combo box, I need to populate the combo with data dependant on the record value. eg for record 1, field Warehouse = 2R so combo would allow selection of locations valid for 2R record 2 has Warehouse = 2M so combo on that row has a selection of locations valid for 2M I can set the combo datasource but can't see...
0
407
by: dbuchanan | last post by:
ComboBox databindng Problem == How the ComboBox is setup and used: My comboBox is populated by a lookup table. The ValueMember is the lookup table's Id and the DisplayMember is the text from a corresponding field in the lookup table. In my data table we store the ID in what I will call the 'key' field. == Description of the desired...
4
4606
by: jon f kaminsky | last post by:
Hi- I've seen this problem discussed a jillion times but I cannot seem to implement any advice that makes it work. I am porting a large project from VB6 to .NET. The issue is using the combo box bound to a table as a lookup, drawing values from another table to populate the available selections. This all worked fine in VB6. I have...
6
2858
by: dbuchanan | last post by:
VS2005 I've been reading all the help I can on the topic (MSDN, other) but I can't make sense of this. Desired behavior; The user is to choose from the displayed list of the databound combobox and the coresponding 'Id' from the lookup table is to be inserted into the field of the new record. I have two simple tables. "tblPerson" is the...
0
2000
by: Frnak McKenney | last post by:
Can I use a bound ComboBox for both browsing and editing? I'm working on a small, standalone database application using Visual C#.NET 2003 and an Access data file. In order to keep the number of different screens down to a minimum, I'm trying to use the same Windows Forms for both browsing and for updating. This works fine for TextBoxes,...
0
7697
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...
0
7924
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. ...
0
8120
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
1
7672
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
7968
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
6283
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...
0
5219
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...
1
1212
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
937
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.