Beginnerprog
New member
- Joined
- Oct 29, 2017
- Messages
- 1
- Programming Experience
- Beginner
I have a problem with two dependent Combobox. I want to do the dependent Comboboxes. When selecting an area in combobox1, a free taxi located in this area should be displayed on combobox2. I found this video on YouTube and tried to use the code in this video https://www.youtube.com/watch?v=n0J_VH6Rh4A. But when I finished, it does not work correctly and shows an error in the code: System.ArgumentException: Binding to a new value member is impossible!
here an error picture
Please help how to fix this?:confusion:
Here the code:
usingMySql.Data.MySqlClient;
namespace check_disp
{
publicpartialclass check2 :Form
{
MySqlConnection connect =newMySqlConnection("datasource=localhost;port=3306;initial catalog=test;username=root;password=");
MySqlCommand cmnd;
MySqlDataAdapter adapt;
DataTable tbl;
public check2()
{
InitializeComponent();
}
privatevoid check2_Load(object sender,EventArgs e)
{
string query ="SELECT `id_loc`, `locations` FROM `local`";
fillcmbo(comboBox1, query,"locations","id_loc");
comboBox1_SelectedIndexChanged(null,null);
}
publicvoid fillcmbo(ComboBox combo,string query,string displayMember,string valueMember)
{
cmnd =newMySqlCommand(query, connect);
adapt =newMySqlDataAdapter(cmnd);
tbl =newDataTable();
adapt.Fill(tbl);
combo.DataSource= tbl;
combo.DisplayMember= displayMember;
combo.ValueMember= valueMember;//showing error here - **Binding to a new value member is impossible**
}
privatevoid comboBox1_SelectedIndexChanged(object sender,EventArgs e)
{
int value;
Int32.TryParse(comboBox1.SelectedValue.ToString(),out value);
string query ="SELECT `id_csl` `id_car`, `id_status`, `id_location` FROM `car_stat_loc` WHERE id_status=1 AND `id_location`="+ value;
fillcmbo(comboBox2, query,"id_car","id_csl");
}
}
}
here an error picture
Please help how to fix this?:confusion:
Here the code:
usingMySql.Data.MySqlClient;
namespace check_disp
{
publicpartialclass check2 :Form
{
MySqlConnection connect =newMySqlConnection("datasource=localhost;port=3306;initial catalog=test;username=root;password=");
MySqlCommand cmnd;
MySqlDataAdapter adapt;
DataTable tbl;
public check2()
{
InitializeComponent();
}
privatevoid check2_Load(object sender,EventArgs e)
{
string query ="SELECT `id_loc`, `locations` FROM `local`";
fillcmbo(comboBox1, query,"locations","id_loc");
comboBox1_SelectedIndexChanged(null,null);
}
publicvoid fillcmbo(ComboBox combo,string query,string displayMember,string valueMember)
{
cmnd =newMySqlCommand(query, connect);
adapt =newMySqlDataAdapter(cmnd);
tbl =newDataTable();
adapt.Fill(tbl);
combo.DataSource= tbl;
combo.DisplayMember= displayMember;
combo.ValueMember= valueMember;//showing error here - **Binding to a new value member is impossible**
}
privatevoid comboBox1_SelectedIndexChanged(object sender,EventArgs e)
{
int value;
Int32.TryParse(comboBox1.SelectedValue.ToString(),out value);
string query ="SELECT `id_csl` `id_car`, `id_status`, `id_location` FROM `car_stat_loc` WHERE id_status=1 AND `id_location`="+ value;
fillcmbo(comboBox2, query,"id_car","id_csl");
}
}
}