昨天遇到的一个问题,我想用一个控件来装载数据库中已存在的所有的产品名称,如有存在,就将其明细加载到下方的表格中,如果不存在,则允许用户新添加一个产品名称,现实现代码如下:

DataTable configinfotype;

string all = this.cbxAffiliatedProject.SelectedValue.ToString();
DataRow[] newRow;

newRow = configinfotype.Select("ProductID=" + all);//查询所属项目为当前选择的产品
AutoCompleteStringCollection ac = new AutoCompleteStringCollection();
foreach (DataRow row in newRow)//添加到提示数据中
{
ac.Add(row["ProductName"].ToString());
}

this.txtFittingsName.AutoCompleteSource = AutoCompleteSource.CustomSource;
this.txtFittingsName.AutoCompleteMode = AutoCompleteMode.SuggestAppend;
this.txtFittingsName.AutoCompleteCustomSource = ac;

configinfotype中存的是从数据库中检索出来的所有记录,可以换成自己查询出来的内容。ProductIDProductName是检索出来的表中的两个列

相关文章:

  • 2021-11-01
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-06-19
  • 2021-11-10
  • 2022-12-23
猜你喜欢
  • 2021-09-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-01-08
  • 2022-02-23
相关资源
相似解决方案