番外篇:、
//该方法是将字符串转化为中文拼音的首写字母大写,
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);
}));
}
原文地址:https://www.cnblogs.com/jiuyueBlog/p/9108563.html