Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

displaying values in a combobox

Posted on 2009-05-13
3
Medium Priority
?
302 Views
Last Modified: 2013-11-26
I am trying to display the stored value of a previously selected item using a combobox. To put it as simply as possible I have a status table which holds the following values
1, proposed
2, accepted
3, denied

When the user is first entering a record they will select one of the statuses displayed in the combobox, then the system will save the numeric value of that item in a table in my database. Then later in time someone will review the proposed item and change the selected value to whichever is appropriate.

If someone selects a value I can store it no problem. the problem rises when someone goes in and reviews a record. I can either get the previously selected value and not display it. (ie I can store the 1 for proposed but the combobox displays an empty string) or I can display the text value of the previously selected item and not have the actual value of the selected item. (ie, display "proposed" in the combobox but the selected value = 0)

Can someone explain to me how I can have my displayed text and my selected value both be correct using vb.net? I have the code I've been trying to get to work below.
cmbStatus.SelectedValue = iStatus
                cmbStatus.SelectedText = dsICMMS.statusTbl.Rows(StatusTblBindingSource.Find("statusID", iStatus)).Item("status")

Open in new window

0
Comment
Question by:ITatIG
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
3 Comments
 
LVL 15

Expert Comment

by:JackOfPH
ID: 24380690
Try this



For ctr as integer = 0 to Combobox1.items.count -1
 
If Combobox1.items.item(ctr) = dsICMMS.statusTbl.Rows(StatusTblBindingSource.Find("statusID", iStatus)).Item("status")
 
Combobox1.SelectedItem = ctr
exit for
end if
 
Next

Open in new window

0
 
LVL 15

Expert Comment

by:JackOfPH
ID: 24380698
oopps typo error...

Try the below code instead...
For ctr as integer = 0 to Combobox1.items.count -1
 
If Combobox1.items.item(ctr) = dsICMMS.statusTbl.Rows(StatusTblBindingSource.Find("statusID", iStatus)).Item("status") then
 
Combobox1.SelectedItem = ctr
exit for
end if
 
Next

Open in new window

0
 
LVL 15

Accepted Solution

by:
JackOfPH earned 500 total points
ID: 24380708
or this one

For ctr as integer = 0 to Combobox1.items.count -1
 
If Combobox1.items.item(ctr) = dsICMMS.statusTbl.Rows(StatusTblBindingSource.Find("statusID", iStatus)).Item("status") then
 
Combobox1.SelectedIndex = ctr
exit for
end if
 
Next

Open in new window

0

Featured Post

Major Serverless Shift

Comparison of major players like AWS, Microsoft Azure, IBM Bluemix, and Google Cloud Platform

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Recently while returning home from work my wife (another .NET developer) was murmuring something. On further poking she said that she has been assigned a task where she has to serialize and deserialize objects and she is afraid of serialization. Wha…
Many of us here at EE write code. Many of us write exceptional code; just as many of us write exception-prone code. As we all should know, exceptions are a mechanism for handling errors which are typically out of our control. From database errors, t…
This course is ideal for IT System Administrators working with VMware vSphere and its associated products in their company infrastructure. This course teaches you how to install and maintain this virtualization technology to store data, prevent vuln…
Add bar graphs to Access queries using Unicode block characters. Graphs appear on every record in the color you want. Give life to numbers. Hopes this gives you ideas on visualizing your data in new ways ~ Create a calculated field in a query: …

721 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question