Good time of day, gentlemen, I'm on the video from youtube here is the link to the video https://www.youtube.com/watch?v=n0J_VH6Rh4A , made the combobox dependency like the video. The bottom line is that the displayed data of the second combobox depended on the first one (for example, when choosing an area, the free machines in the area should be displayed), but there is no result. tell me the options how to implement?

Here is the C # code:

using MySql.Data.MySqlClient; namespace check2 { public partial class check2 : Form { MySqlConnection connect = new MySqlConnection("datasource=localhost;port=3306;initial catalog=test;username=root;password="); MySqlCommand cmnd; MySqlDataAdapter adapt; DataTable tbl; public check2() { InitializeComponent(); } private void check2_Load(object sender, EventArgs e) { string query = "SELECT `id_loc`, `locations` FROM `local`"; fillcmbo(comboBox1, query, "location", "id_loc"); comboBox1_SelectedIndexChanged(null,null); } public void fillcmbo(ComboBox combo, string query, string displayMember, string valueMember) { cmnd = new MySqlCommand(query, connect); adapt = new MySqlDataAdapter(cmnd); tbl = new DataTable(); adapt.Fill(tbl); combo.DataSource = tbl; combo.DisplayMember = displayMember; combo.ValueMember = valueMember; } private void comboBox1_SelectedIndexChanged(object sender, EventArgs e) { int val; Int32.TryParse(comboBox1.SelectedValue.ToString(), out val); string query = "SELECT `id_car`, `id_status`, `id_location` FROM `car_stat_loc` WHERE `id_location`=" +val; fillcmbo(comboBox2, query, "location", "id_loc"); } } } 

Here is a screenshot of the error: https://i.stack.imgur.com/eQyss.jpg

  • And what is the result? Do you have the first combobox displays a list of cities? - Bulson
  • City is a typo, when choosing a district, cars with statuses equal to 1 (that is, free) should be displayed. the result should be like this! - beginneroot
  • Check your settings: in the first call to locations and location . In the second, instead of location and id_loc , probably there should be id_location and id_car or id_status . - Alexander Petrov
  • here on combo.ValueMember = valueMember; gives an error when starting the application - beginneroot
  • What mistake? Provide all relevant information. - Alexander Petrov

0