473,320 Members | 1,825 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

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

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>research</summary>

</tblTasks>

<tblTasks>

<id>717</id>

<summary>Other - time estimation</summary>

</tblTasks>

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

cboTasks.DataSource = null;

cboTasks.Items.Clear();

cboTasks.DataSource = oDataSet;

cboTasks.DisplayMember = "tblTasks.summary";

cboTasks.ValueMember = "tblTasks.id";

but the "-- Select Task --" option is showin up last. any idea why or how to
fix?
Nov 17 '05 #1
2 1528
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.Sort =
"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>research</summary>

</tblTasks>

<tblTasks>

<id>717</id>

<summary>Other - time estimation</summary>

</tblTasks>

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

cboTasks.DataSource = null;

cboTasks.Items.Clear();

cboTasks.DataSource = oDataSet;

cboTasks.DisplayMember = "tblTasks.summary";

cboTasks.ValueMember = "tblTasks.id";

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.googlegr oups.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.Sort =
"ascending";
thanks lars.
i've revised the code as per your instrucitons:
cboTasks.DataSource = oDataSet.Tables["tblTasks"].DefaultView.Sort = "id";
cboTasks.DisplayMember = "summary";

cboTasks.ValueMember = "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.DataViewRowState.CurrentRows);

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>research</summary>

</tblTasks>

<tblTasks>

<id>717</id>

<summary>Other - time estimation</summary>

</tblTasks>

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

cboTasks.DataSource = null;

cboTasks.Items.Clear();

cboTasks.DataSource = oDataSet;

cboTasks.DisplayMember = "tblTasks.summary";

cboTasks.ValueMember = "tblTasks.id";

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
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 =...
2
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,...
0
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...
2
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...
6
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...
0
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...
4
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...
6
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...
0
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...
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

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.