ComboBox Problem
I'm populating a ComboBox from a database using a stored procedure and then setting its DropDownStyle to DropDownList so that a user can only select the values I've set for it after the initial population from the stored procedure. The trouble is that I can populate it just fine if the style is set to DropDown, but then the user can just type anything under the sun (which I definitely don't want). But if I set the style to DropDownList, even after the sproc call, my database value doesn't appear in the box. I'm fairly new to C#, but figure this should be able to work?
Code below....
This is in the form load (ComboBox style and its values)*
private void ClientList_Load(object sender, EventArgs e)
{
cmbSelectType.DropDownStyle = ComboBoxStyle.DropDownList;
cmbTitle.Items.Add("Dr.");
cmbTitle.Items.Add("Mr.");
cmbTitle.Items.Add("Ms.");
cmbTitle.Items.Add("Mrs.");
...
*This is in the "Get Clients" button to pull data to title ComboBox*
SqlConnection conn = new SqlConnection(connectionString);
SqlCommand cmd = new SqlCommand("uspGetClients", conn);
conn.Open();
cmd.CommandType = CommandType.StoredProcedure;
SqlDataAdapter DA = new SqlDataAdapter(cmd);
DataSet DS = new DataSet();
cmd.Parameters.Add("@SelectType", SqlDbType.VarChar, 20).Value = Convert.ToString(cmbSelectType.Text);
cmd.Parameters.Add("@SelectRegion", SqlDbType.VarChar, 20).Value = Convert.ToString(cmbSelectRegion.Text);
DataTable Client = new DataTable();
DA.Fill(Client);
int rowPosition = 0;
cmbTitle.Text = Client.Rows[rowPosition]["Title"].ToString();
|