Solved

displaying values in a combobox

Posted on 2009-05-13
3
296 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
  • 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 125 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

On Demand Webinar - Networking for the Cloud Era

This webinar discusses:
-Common barriers companies experience when moving to the cloud
-How SD-WAN changes the way we look at networks
-Best practices customers should employ moving forward with cloud migration
-What happens behind the scenes of SteelConnect’s one-click button

Question has a verified solution.

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

Suggested Solutions

Summary Displaying images in RichTextBox is a common requirement with limited solutions available. Pasting through clipboard or embedding into RTF content only support static images.  This article describes how to insert Windows control objects int…
Welcome my friends to the second instalment and follow-up to our Minify and Concatenate Your Scripts and Stylesheets (http://www.experts-exchange.com/Programming/Languages/.NET/ASP.NET/A_4334-Minify-and-Concatenate-Your-Scripts-and-Stylesheets.html)…
Email security requires an ever evolving service that stays up to date with counter-evolving threats. The Email Laundry perform Research and Development to ensure their email security service evolves faster than cyber criminals. We apply our Threat…
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…

685 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