我有一个带有两个组合框的 Windows 窗体,每个组合框都使用 DataSet 和 TableAdapter 填充。ComboBox1
包含员工的姓名并ComboBox2
包含分配给所有员工的区域。我希望能够选择员工的姓名并过滤ComboBox2
以仅显示员工分配的地区。
这是我到目前为止得到的:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace Prueba2
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
public void LlenaEmpleados()
{
DataSet1 ds = new DataSet1();
DataSet1TableAdapters.EmployeesTableAdapter Adapter = new DataSet1TableAdapters.EmployeesTableAdapter();
Adapter.FillEmployees(ds.Employees);
ds.Employees.Columns.Add("FullName", typeof(string), "FirstName +' '+ LastName");
cbPrimero.DataSource = ds.Tables["Employees"];
cbPrimero.DisplayMember = "FullName";
cbPrimero.ValueMember = "EmployeeID";
}
public void LlenaTerritorios()
{
DataSet1 ds = new DataSet1();
DataSet1TableAdapters.TerrioriosTableAdapter Adapter = new DataSet1TableAdapters.TerrioriosTableAdapter();
Adapter.FillTerritorios(ds.Territorios);
cbSegundo.DataSource = ds.Tables["Territorios"];
cbSegundo.DisplayMember = "TerritoryDescription";
cbSegundo.ValueMember = "EmployeeID";
}
private void Form1_Load(object sender, EventArgs e)
{
LlenaEmpleados();
cbPrimero.Text = "";
LlenaTerritorios();
cbSegundo.Text = "";
}
private void cbPrimero_SelectedIndexChanged(object sender, EventArgs e)
{
cbPrimero.AutoCompleteSource = AutoCompleteSource.ListItems;
cbPrimero.AutoCompleteMode = AutoCompleteMode.SuggestAppend;
}
}
}
我已经搜索了解决方案,但他们使用不使用 DataSet 的 SQL 查询来完成。