473,388 Members | 1,574 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,388 software developers and data experts.

combo problem

hi i have a combobox which has some values
like (eg)
a
b
c
d
i want to retrieve the value from the db (a, or b or c or d)
and then select that item in the combo according ly

foreach (DataRow dr in recs)
{
cmbType.SelectedText = dr["description"].ToString();
}

but this doesnt work
dr["description"] has the correct value i want to select in the combo
Nov 15 '05 #1
7 1308
I believe the SelectedText property returns the description of the current
item. I think what you want is

cmbType.items.add(dr["description"].ToString());
"drishtik" <sh*****@hotmail.com> wrote in message
news:Oo**************@TK2MSFTNGP09.phx.gbl...
hi i have a combobox which has some values
like (eg)
a
b
c
d
i want to retrieve the value from the db (a, or b or c or d)
and then select that item in the combo according ly

foreach (DataRow dr in recs)
{
cmbType.SelectedText = dr["description"].ToString();
}

but this doesnt work
dr["description"] has the correct value i want to select in the combo

Nov 15 '05 #2
hi all the items are already loaded in the combo box.
if the query from the database returns a "b"
i want to select b in the combo.
thanx
Nov 15 '05 #3
Sorry, I misunderstood.

Why is your statement in a foreach loop? How many records are in your
dataset? If there is more than one, wouldn't they all just be overwritten
except for the last one?
"drishtik" <sh*****@hotmail.com> wrote in message
news:Oj**************@tk2msftngp13.phx.gbl...
hi all the items are already loaded in the combo box.
if the query from the database returns a "b"
i want to select b in the combo.
thanx

Nov 15 '05 #4
it has only 1 record.

"Jeff Molby" <JeffMolby@C_mc_st.n_t> wrote in message
news:uD**************@tk2msftngp13.phx.gbl...
Sorry, I misunderstood.

Why is your statement in a foreach loop? How many records are in your
dataset? If there is more than one, wouldn't they all just be overwritten
except for the last one?
"drishtik" <sh*****@hotmail.com> wrote in message
news:Oj**************@tk2msftngp13.phx.gbl...
hi all the items are already loaded in the combo box.
if the query from the database returns a "b"
i want to select b in the combo.
thanx


Nov 15 '05 #5
Are there many items in your combo? If not, I'd just loop through everything
in the combo.Items collection. When you find the one that matches, set the
Selected property of the Item = true.

If there are a lot of items, this is probably inefficient. In that case, I'd
try using the SelectedValue property.

If that doesn't work, post the rest of your code and I'll see if I can
figure out what's going wrong.

"drishtik" <sh*****@hotmail.com> wrote in message
news:Oz**************@TK2MSFTNGP11.phx.gbl...
thts exactly what i tried but it doesnt get selected. and always gives a
null

cmbType.SelectedText = dr["description"].ToString();

Nov 15 '05 #6
hi thanx for the reply

id like to use the selectedvalue property too

dsCar = ser.getAllCars();
DataRow[] recs = dsCar.Tables[0].Select("Carid = " +
txCarID.Text.ToString());
foreach (DataRow dr in recs) //if i have only 1 record, i dont need this
loop but how do i get the value in recs?
{
cmbType.SelectedValue = dr["description"].ToString();
cmbCars.SelectedValue = dr["name"].ToString();
}

also how do i loop thru all the items in a combo?

thanx
Nov 15 '05 #7
foreach (ListItem li in cmbType.Items)
{
if (li.Text = dr["description"].ToString())
{li.Selected = true;}
}

I'm mostly a VB developer, so my syntax may be crap, but hopefully you get
the idea.

"drishtik" <sh*****@hotmail.com> wrote in message
news:OD**************@TK2MSFTNGP09.phx.gbl...
hi thanx for the reply

id like to use the selectedvalue property too

dsCar = ser.getAllCars();
DataRow[] recs = dsCar.Tables[0].Select("Carid = " +
txCarID.Text.ToString());
foreach (DataRow dr in recs) //if i have only 1 record, i dont need this
loop but how do i get the value in recs?
{
cmbType.SelectedValue = dr["description"].ToString();
cmbCars.SelectedValue = dr["name"].ToString();
}

also how do i loop thru all the items in a combo?

thanx

Nov 15 '05 #8

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

Similar topics

4
by: Heather | last post by:
Hi I am desparately looking for advice in relation to storing the results after selecting items from two combo boxes on a Referral form. The first combo box 'ctl Type' displays a full list of...
1
by: Jeff Smith | last post by:
Hi This is a repost due to no responses Here's a problem I've encountered with Access 2003 which has got me to redesign how I get the row source in a second combo box using the first combo...
9
by: Edwinah63 | last post by:
Hi everyone, Please let there be someone out there who can help. I have two BOUND combo boxes on a continuous form, the second being dependent on the first. I have no problem getting the...
7
by: Ausclad | last post by:
Ok, ill try again..... It seems fairly simple. I have two combo boxes in a datagrid. The datagrid is bound to a a table in a dataset. The two combo boxes are bound to a single data table...
1
by: lawton | last post by:
Source: this is an access 2003 question My knowledge level: reading books, internet, and trial & error; no formal training I'm trying to get a running sum of what's filtered in a subform which is...
4
by: Dave | last post by:
I wasn't sure how to search for previous posts about this, it felt real specific. Ok so here's the database & problem: I have 4 combo boxes: cboServer, cboPolicy, cboDB, and cboApplication. ...
2
by: biganthony via AccessMonster.com | last post by:
Hi, I decided to install Office 2003 Service Pack 3 on my home computer to test (in full knowledge that there may be some issues with it). After installation, I have noticed that with a small...
3
rhitam30111985
by: rhitam30111985 | last post by:
Hi all.. i am trying to create a combo with the pop down list being modfied in real time as i type each character : import gtk window=gtk.Window(gtk.WINDOW_TOPLEVEL)...
6
by: =?Utf-8?B?amVmZmVyeQ==?= | last post by:
i need help with a combo box and this same code works on my first tab with a combo box. The error or problem i have is this code causes an index out of range error when i run it on my second combo...
3
by: evenlater | last post by:
Using Access 2007, I've found that combo box back colors change to transparent from normal inconsistently for no reason I can discern. Never had that problem in previous versions of Access. I do...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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
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
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
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...

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.