Solved

displaying values in a combobox

Posted on 2009-05-13
3
292 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
Comment Utility
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
Comment Utility
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
Comment Utility
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

Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

Join & Write a Comment

Suggested Solutions

Normally the drop down box control found in the .Net framework tools is able to select just one data and value at a time, which is displayed on the text area.   But what if you want to have multiple values to be selected in the drop down box? As …
It seems a simple enough task, yet I see repeated questions asking how to do it: how to pass data between two forms. In this article, I will show you the different mechanisms available for you to do just that. This article is directed towards the .N…
This video discusses moving either the default database or any database to a new volume.
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…

772 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

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now