dev 中 字符串转中文拼音缩写,对grid列表进行模糊匹配,grid获取焦点行,gridlookupedit控件用拼音模糊匹配下拉选项
Posted 酒乐
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了dev 中 字符串转中文拼音缩写,对grid列表进行模糊匹配,grid获取焦点行,gridlookupedit控件用拼音模糊匹配下拉选项相关的知识,希望对你有一定的参考价值。
番外篇:、
//该方法是将字符串转化为中文拼音的首写字母大写,
public static string RemoveSpecialCharacters(string str)
{
try
{
if (string.IsNullOrWhiteSpace(str)) { return str; }
var result = Regex.Replace(str, "[^0-9A-Za-z]", "");
if (string.IsNullOrWhiteSpace(result)) { return "0"; }
return result;
}
catch (Exception ex)
{
//Logger.Error("移除字符串中的特殊字符", ex);
return string.Empty;
}
}
//在文本框中输入拼音,根据拼音匹配grid的数据
this.gdv_PQConfigure.ActiveFilter.NonColumnFilter
= string.Format("[NAME_PINYIN] like ‘%{0}%‘ OR [DEPT_PINYIN] like ‘%{0}%‘", this.lentxt_Search.Text); //NAME_PINYIN和DEPT_PINYIN是grid的felidname绑定的列名。
//grid获取焦点行
private void FocusRowColumn(GridView gdv, int rowHandle, string columnName)
{
gdv.FocusedRowHandle = rowHandle;
gdv.FocusedColumn = gdv.Columns[columnName];
gdv.ShowEditor();
}
//gridlookupedit用拼音模糊匹配下拉选项
private void User_FilterLookup(object sender)
{
GridLookUpEdit edit = sender as GridLookUpEdit;
GridView gridView = edit.Properties.View as GridView;
FieldInfo fi = gridView.GetType().GetField("extraFilter", BindingFlags.NonPublic | BindingFlags.Instance);
BinaryOperator op2 = new BinaryOperator("PINYIN", edit.AutoSearchText + "%", BinaryOperatorType.Like);
BinaryOperator op3 = new BinaryOperator("PINYIN", "%" + edit.AutoSearchText + "%", BinaryOperatorType.Like);
BinaryOperator op1 = new BinaryOperator("NAME", "%" + edit.AutoSearchText + "%", BinaryOperatorType.Like); //name是要匹配的实体字段名
string filterCondition = new GroupOperator(GroupOperatorType.Or, new CriteriaOperator[] { op1, op2, op3 }).ToString();
fi.SetValue(gridView, filterCondition);
MethodInfo mi = gridView.GetType().GetMethod("ApplyColumnsFilterEx", BindingFlags.NonPublic | BindingFlags.Instance);
mi.Invoke(gridView, null);
}
//在事件中调用
private void repEditUser_EditValueChanging(object sender, DevExpress.XtraEditors.Controls.ChangingEventArgs e)
{
var _Handle = this.Handle;
BeginInvoke(new MethodInvoker(delegate ()
{
User_FilterLookup(sender);
}));
}
以上是关于dev 中 字符串转中文拼音缩写,对grid列表进行模糊匹配,grid获取焦点行,gridlookupedit控件用拼音模糊匹配下拉选项的主要内容,如果未能解决你的问题,请参考以下文章