zoukankan      html  css  js  c++  java
  • 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;

    附上代码 下载

  • 相关阅读:
    修改spring MVC配置文件的默认位置
    TCP三次握手四次挥手视频讲解
    Redis端口配置
    applicationContext-redis.xml
    PageHelper的分页原理
    maven的三种工程 pom工程、jar工程、war工程的区别和使用
    springboot 整合spring Data JPA的资源配置pom.xml
    Spring知识点整理
    jdk1.6 和 jdk1.7 区别
    linux中安装redis
  • 原文地址:https://www.cnblogs.com/feng84/p/2804057.html
Copyright © 2011-2022 走看看