Quantcast
Channel: Visual C# forum
Viewing all articles
Browse latest Browse all 31927

combobox SelectionChanged in wpf

$
0
0

Hi,

   i have 2 combo box  and one text box...namely cmbxemployername,cmbxlocation and tbdepartment i loaded cmbxemployername from sql..now i want load cmbxlocation based on cmbxemployername current item... i used some coding but i got error ..may i know how to do this .....

my coding.....

 private void cmbxemployername_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            ComboBoxItem currentItem = ((System.Windows.Controls.ComboBoxItem)cmbxemployername.SelectedItem);
            cmbxlocation.Items.Clear();
            con = new SqlConnection(cn);
            con.Open();
            SqlCommand cmd = new SqlCommand("cityload", con);
            cmd.CommandType = CommandType.StoredProcedure;
            cmd.Parameters.AddWithValue("@company", currentItem.Content.ToString());
            SqlDataReader dr = cmd.ExecuteReader();
            while (dr.Read())
            {
                cmbxlocation.Items.Add(dr[0].ToString());
            }
            con.Close();
        }

Error as ..  Unable to cast object of type 'System.String' to type 'System.Windows.Controls.ComboBoxItem'.


Viewing all articles
Browse latest Browse all 31927

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>