Click here to Skip to main content
15,896,453 members

Why I can't select the values from the combobox?

Eliza Maria asked:

Open original thread
I have a project in winforms and in my RegisterStudent form I have a combobox that hold education column.Based on the selection from the combobox,a selection of checkboxes will appear.The problem is that when i want to select a value from the combobox,i can't.Instead the courses for the default value appears.This is my method to load data into the combobox:
private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)
{
    LoadEducation();
}
private void LoadEducation()
{
    using (SqlConnection conn = new SqlConnection(connstr))
    {
        try
        {
            string query = "select  education from AvailableCourses";

            da = new SqlDataAdapter(query, conn);
            conn.Open();
            ds = new DataSet();
            da.Fill(ds, "AvailableCourses");
            comboBoxEducation.DisplayMember = "education";
            comboBoxEducation.ValueMember = "education";
            comboBoxEducation.DataSource = ds.Tables["AvailableCourses"];
        }
        catch (Exception ex)
        {
            // write exception info to log or anything else
            MessageBox.Show("Error occured!");
        }
    }
}

And this is the table from where i take the data:
CREATE TABLE [dbo].[AvailableCourses](
	[CourseID] [char](10) NOT NULL,
	[ClassID] [nvarchar](50) NULL,
	[courseName] [nvarchar](50) NOT NULL,
	[education] [nvarchar](50) NOT NULL,
PRIMARY KEY CLUSTERED 
(
	[CourseID] ASC


What I have tried:

Does anybody have any idea why is not working?I have also tried with SelectedIndex and SelectedValue but for nothing,it won't do anything.Thank you in advance.
Tags: C#, MySQL

Plain Text
ASM
ASP
ASP.NET
BASIC
BAT
C#
C++
COBOL
CoffeeScript
CSS
Dart
dbase
F#
FORTRAN
HTML
Java
Javascript
Kotlin
Lua
MIDL
MSIL
ObjectiveC
Pascal
PERL
PHP
PowerShell
Python
Razor
Ruby
Scala
Shell
SLN
SQL
Swift
T4
Terminal
TypeScript
VB
VBScript
XML
YAML

Preview



When answering a question please:
  1. Read the question carefully.
  2. Understand that English isn't everyone's first language so be lenient of bad spelling and grammar.
  3. If a question is poorly phrased then either ask for clarification, ignore it, or edit the question and fix the problem. Insults are not welcome.
  4. Don't tell someone to read the manual. Chances are they have and don't get it. Provide an answer or move on to the next question.
Let's work to help developers, not make them feel stupid.
Please note that all posts will be submitted under the http://www.codeproject.com/info/cpol10.aspx.



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900