zoukankan      html  css  js  c++  java
  • C#中ComboBox的模糊搜索

       给出一段模糊文字,让ComboBox自动改变SelectedIndex,传统方法是用for循环来完成,这里另一种实现方法,供新手学习。

       SendMessage属于消息类API函数,具体介绍大家可以自己翻阅资料,下面给出实现方法:


    1、引用类库 

        
    using System.Runtime.InteropServices;    //API调用需要引用这个类库

    2、声明函数和常量

          [DllImport(
    "user32.dll", EntryPoint="SendMessageA")]    //引用SendMessage API

          
    private static extern int SendMessage (IntPtr hwnd, int wMsg, IntPtr wParam,  string lParam);

          
    const int CB_FINDSTRING = 0x14C//声明查找字符串的常数          

    3、调用

        
    string s =textBox1.Text;    //获取TextBox1的值 

        
    int i=SendMessage(this.comboBox1.Handle, CB_FINDSTRING, IntPtr.Zero, s);  

         comboBox1.SelectedIndex
    =i;    //根据查找结果给ComboBox赋值         
  • 相关阅读:
    整合规则引擎urule
    vue学习
    发送put请求,get请求
    jpa自定义字段
    spring的3种配置方式
    netty
    springsercurity和shiro
    git报错
    Scrapy全站数据爬取
    python操作Excel模块openpyxl
  • 原文地址:https://www.cnblogs.com/habin/p/1419862.html
Copyright © 2011-2022 走看看