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
locationsandlocation. In the second, instead oflocationandid_loc, probably there should beid_locationandid_carorid_status. - Alexander Petrov