使用组合框(使用数据绑定项)填充列表框

时间:2018-05-17 15:33:03

标签: c#

如何使用select query(源自组合框,数据绑定项)填充列表框

如果在组合框中选择了“多冰淇淋”,​​那么我希望系统选择该行并显示我的列表框中“过程”列中的内容

目前,该软件正在返回该列下的所有行

MAcon.Open();
 OleDbDataAdapter da = new OleDbDataAdapter("Select * from [Product Family] Where Process = @Process", MAcon);
 da.SelectCommand.Parameters.AddWithValue("@Process", ItemCBx.Text);
 DataTable dtbl = new DataTable();
 da.Fill(dtbl);
 if (dtbl.Rows.Count == 1)
 {
     Listbox1.Text.ToString().Split(',').ToList().ForEach(c => Listbox1.Items.Add(c.Trim()));
     Define.SelectedIndex = 1;
 }

MAcon.Close();

1 个答案:

答案 0 :(得分:0)

当用户在comboBox中选择某些内容时,您需要添加一个eventHandler。

然后获取Top 10 allocations by size Allocation Size - 1045632 5.98 MBytes Allocation Size - 1048560 3 MBytes Allocation Size - 1024000 1000 KBytes Allocation Size - 1013248 989.5 KBytes Allocation Size - 1005440 981.88 KBytes Allocation Size - 1001216 977.75 KBytes Allocation Size - 962528 939.97 KBytes Allocation Size - 961272 938.74 KBytes Allocation Size - 938088 916.1 KBytes Allocation Size - 924672 903 KBytes ------------------------------------- Top 10 allocations by count Allocation Size - 1045632 6 allocations(s) Allocation Size - 1048560 3 allocations(s) Allocation Size - 17152 3 allocations(s) Allocation Size - 261120 2 allocations(s) Allocation Size - 48896 1 allocations(s) Allocation Size - 86784 1 allocations(s) Allocation Size - 96512 1 allocations(s) Allocation Size - 98952 1 allocations(s) Allocation Size - 117248 1 allocations(s) Allocation Size - 132160 1 allocations(s) 之类的selectedItem并将其传递给查询。

comboBox1.SelectedItem.ToString()

然后

da.SelectCommand.Parameters.AddWithValue("@Process",comboBox1.SelectedItem.ToString()); 

问题:我不知道你的查询返回的内容是if (dtbl.Rows.Count == 1) { // Selects the value located in teh first row and first columns // if that is what your query is returning listBox1.Items.Add(dtbl.Rows[0][0]); } 表示它会返回多列,你只能在列表框中每行有一个元素,我建议使用dataGridView控件和{ {1}}它将显示所有返回的列。