Solved

displaying values in a combobox

Posted on 2009-05-13
3
299 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 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

Interactive Way of Training for the AWS CSA Exam

An interactive way of learning that will help you visualize core concepts so that you can be more effective when taking your AWS certification exam.  Built for students by a student to help them understand the concepts that they are being taught.

Question has a verified solution.

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

The object model of .Net can be overwhelming at times – so overwhelming that quite trivial tasks often take hours of research. In this case, the task at hand was to populate the datagrid from SQL Server database in Visual Studio 2008 Windows applica…
Today I had a very interesting conundrum that had to get solved quickly. Needless to say, it wasn't resolved quickly because when we needed it we were very rushed, but as soon as the conference call was over and I took a step back I saw the correct …
Visualize your data even better in Access queries. Given a date and a value, this lesson shows how to compare that value with the previous value, calculate the difference, and display a circle if the value is the same, an up triangle if it increased…
Sometimes it takes a new vantage point, apart from our everyday security practices, to truly see our Active Directory (AD) vulnerabilities. We get used to implementing the same techniques and checking the same areas for a breach. This pattern can re…

628 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