通用的输入检索匹配C# 模糊匹配


#region 给控件赋值

public void SetList<T>(List<T> li, string propertyname)
{
#region 赋值
this.Height = 25;


Type type = typeof(T);

PropertyInfo property = type.GetProperty(propertyname);


// var pp = tt.GetType().GetProperty(propertyname).Name;
#endregion
#region 匹配

txtValue.TextChanged += (x, y) =>
{

TextBox cb = x as TextBox;
var lp2 = (from t in li select t.GetType().GetProperty(propertyname).GetValue(t)).ToList();

var lp = (from t in li where (t.GetType().GetProperty(propertyname).GetValue(t).ToString()).Contains(cb.Text) select t.GetType().GetProperty(propertyname).GetValue(t)).ToList();
this.lstItems.DataSource = lp;

this.Height = 150;


};

#endregion
#region 取值

lstItems.Click += (x, u) =>

ListBox cb = x as ListBox;
if (cb.Items.Count > 0)
{
this.txtValue.Text = cb.Items[cb.SelectedIndex].ToString();
}

this.Height = 25;
};


txtValue.LostFocus += (x, y) =>
{
TextBox cb = x as TextBox;


};

//lstItems.LostFocus += (x, y) =>
//{

// this.Height = 25;
//};


#endregion


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM