【发布时间】:2019-04-05 15:18:50
【问题描述】:
来自两个组合框的项目列表是相同的。我的问题是,如果我从第一个组合框中选择一个项目,我想从第二个组合框中删除或不显示该项目,但该项目将保留在第一个组合框中。
//////////////this is how i fill combobox
public void fillcombobox()
{
String selectQuery = "SELECT * FROM candidate_list";
connection.Open();
cmd = new MySqlCommand(selectQuery, connection);
mdr = cmd.ExecuteReader();
try
{
while (mdr.Read())
{
if (mdr.GetString("candidate_position").Equals("PRO"))
{
//PRO1
cbo_Pro1.Text = "-- SELECT CANDIDATE --";
cbo_Pro2.Text = "-- SELECT CANDIDATE --";
string fname = mdr.GetString("candidate_name");
string spacee = " ";
string lname = mdr.GetString("candidate_surname");
cbo_Pro1.Items.Add(fname + spacee + lname);
cbo_Pro2.Items.Add(fname + spacee + lname);
}
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
connection.Close();
}
////////////this is the event for 1st combobox
private void cbo_Pro1_SelectedIndexChanged(object sender, EventArgs e)
{
pro1Name = cbo_Pro1.Text.Split(null);
String selectQuery = "Select * FROM candidate_list WHERE candidate_name LIKE '%" + pro1Name[0] + "%'";
cmd = new MySqlCommand(selectQuery, connection);
da = new MySqlDataAdapter(cmd);
DataTable table = new DataTable();
da.Fill(table);
byte[] image = (byte[])table.Rows[0][5];
pictureBox8.Image = byteArrayToImage(image);
da.Dispose();
}
//////////////////this is the event for second combobox
private void cbo_Pro2_SelectedIndexChanged(object sender, EventArgs e)
{
pro2Name = cbo_Pro2.Text.Split(null);
String selectQuery = "Select * FROM candidate_list WHERE candidate_name LIKE '%" + pro2Name[0] + "%'";
cmd = new MySqlCommand(selectQuery, connection);
da = new MySqlDataAdapter(cmd);
DataTable table = new DataTable();
da.Fill(table);
byte[] image = (byte[])table.Rows[0][5];
pictureBox9.Image = byteArrayToImage(image);
da.Dispose();
}
【问题讨论】:
-
你应该做的是创建一个可以过滤的主视图,不需要每次都加载数据......然后你过滤视图......