Solved

What combobox property must be filled to make a choosen option reflect  a correspondent code?

Posted on 2014-01-22
3
261 Views
Last Modified: 2014-01-22
Hi Experts!

What combobox property must be filled to make a choosen option reflect  a correspondent code?

Example:

Combo:
01
BD table:
02

The code I used:

.....
 using (var connection = new MySqlConnection(connectionString))
            {
                connection.Open();
                var query = "SELECT SB_CR, DESCRICAO FROM cr WHERE TIPO=1";
                using (var command = new MySqlCommand(query, connection))
                {
                    using (var reader = command.ExecuteReader())
                    {
                        //Iterate through the rows and add it to the combobox's items
                        while (reader.Read())
                        {
                            comboBox1.Items.Add(reader.GetString("DESCRICAO"));

                           // It doesn't work
                           //comboBox1.ValueMember = reader.GetString("SB_CR");

                        }
                    }
                }

Open in new window


So If I choose CASA a correspondent property containing the PK  101 must be available to be used by the program. What's the property ?


Thanks in advance!
0
Comment
Question by:Eduardo Fuerte
  • 2
3 Comments
 
LVL 26

Accepted Solution

by:
Shaun Kline earned 500 total points
ID: 39799868
ValueMember and DisplayMember are used for databinding your combo box to a datasource, such as a DataSet.

If you want to use a SQLDataReader, you will need to create a ComboBoxItem, set its Content and Tag properties and then add it to your ComboBox.
0
 

Author Comment

by:Eduardo Fuerte
ID: 39800284
Hello

Really much easier using Dataset than code as I did.
I had only to turn off constraints in dataset for my particular purpose.
and simply use

  var teste1 = this.comboBox1.SelectedValue;
0
 

Author Closing Comment

by:Eduardo Fuerte
ID: 39800864
Ok
0

Featured Post

3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Need a complete list of ASP.NET page load events 3 29
About delegates in c sharp 3 38
C# HTTP GET method sample code 3 42
Code works but it's slow 24 45
Wouldn’t it be nice if you could test whether an element is contained in an array by using a Contains method just like the one available on List objects? Wouldn’t it be good if you could write code like this? (CODE) In .NET 3.5, this is possible…
This article shows how to deploy dynamic backgrounds to computers depending on the aspect ratio of display
This tutorial gives a high-level tour of the interface of Marketo (a marketing automation tool to help businesses track and engage prospective customers and drive them to purchase). You will see the main areas including Marketing Activities, Design …
Migrating to Microsoft Office 365 is becoming increasingly popular for organizations both large and small. If you have made the leap to Microsoft’s cloud platform, you know that you will need to create a corporate email signature for your Office 365…

863 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

26 Experts available now in Live!

Get 1:1 Help Now