• winform一个带自动完成功能的TextBox


    一个winform带自动完成功能的TextBox,效果如下图,当TextBox输入字符时,按文本框中的内容查找数据,并绑定在下拉的DataGridView

    使用方法如下,控件数据源为List<T>

    private void FrmMaterialsRequisitionBill_Load(object sender, EventArgs e)//窗体加载
    
    {
    
    this.txtMaterialType.Mapping.Add("编码", "TypeNO");//编码为DataGridView要显示的列名,"TypeNO"绑定的字段。
    
    this.txtMaterialType.Mapping.Add("类型名称", "TypeName");//如有多列使用Mapping.Add();即可
    
    this.txtMaterialType.Mapping.Add("拼音码", "PinyinCode");
    
    this.txtMaterialType.Mapping.Add("备注", "Remark");
    
    this.txtMaterialType.DisplayMember = "TypeName";//DisplayMember指定在TextBox上显示的字段值
    
    
    //文本值改变时 
    
    this.txtMaterialType.PropertyChanged += new PropertyChangedEventHandler(RequisitionType_PropertyChanged); 
    
    }
    
    //数据绑定
    
    public void RequisitionType_PropertyChanged(object sender, PropertyChangedEventArgs e)
    
    {
    
      string requisitionType= txtMaterialType.DisplayValue;//取出TextBox显示的本文值
    
      
      this.txtMaterialType.DataSource = requisitionTypeDAL.GetList(temp.TypeName.Contains(requisitionType)).ToList();// 模拟在数据库中查找数据,然后通过DataSource 绑定   
    
    }
    

      

    //取值,控件中保存的是List<T>的泛型对象,通过Target取值,MaterialsRequisitionType为泛型中的实际对象

    MaterialsRequisitionType requisitionType = txtMaterialsRequisitionType.Target  as   MaterialsRequisitionType;

    附上代码 下载

  • 相关阅读:
    判断DataReader中是否有指定列
    datatable dateset 载体传递数据、存储过程
    抓取网页信息
    捕获异常 winform
    修改myeclipse的jsp模板
    包装设计模式的实现以改进BufferedReader中的readLine方法为例
    查询图书馆借书情况-代码
    查询四六级成绩
    Sqlyog增加试用期
    MVC笔记-模板页布局
  • 原文地址:https://www.cnblogs.com/feng84/p/2804057.html
Copyright © 2020-2023  润新知