我正在尝试改进AutoFilterRow
我的专栏之一的功能。该列将始终由一个字符串组成,该字符串表示一系列值,如下所示:"num1 - num2"
. 我想允许最终用户AutoFilterRow
在该特定列中的单元格中键入一个值,并且其部分的范围包含他们键入的数字的行。例如,如果我有 3 行,并且它们的每个部分属性如下:"1 - 4"
、"1 - 6"
和,并且用户在此列的单元格中"4 - 6"
键入,我希望行包含和。"3"
AutoFilterRow
"1 - 4"
"1 - 6"
我已经覆盖了CreateAutoFilterCriterion
inMyGridView
以允许附加运算符,如本网站上的几个示例中所建议的:
protected override CriteriaOperator CreateAutoFilterCriterion(GridColumn column, AutoFilterCondition condition, object _value, string strVal)
{
if ((column.ColumnType == typeof(double) || column.ColumnType == typeof(float) || column.ColumnType == typeof(int)) && strVal.Length > 0)
{
BinaryOperatorType type = BinaryOperatorType.Equal;
string operand = string.Empty;
if (strVal.Length > 1)
{
operand = strVal.Substring(0, 2);
if (operand.Equals(">="))
type = BinaryOperatorType.GreaterOrEqual;
else if (operand.Equals("<="))
type = BinaryOperatorType.LessOrEqual;
else if (operand.Equals("<>"))
type = BinaryOperatorType.NotEqual;
}
if (type == BinaryOperatorType.Equal)
{
operand = strVal.Substring(0, 1);
if (operand.Equals(">"))
type = BinaryOperatorType.Greater;
else if (operand.Equals("<"))
type = BinaryOperatorType.Less;
else if (operand.Equals("!") || operand.Equals("~"))
type = BinaryOperatorType.NotEqual;
}
if (type != BinaryOperatorType.Equal)
{
string val = strVal.Replace(operand, string.Empty);
try
{
if (!val.IsEmpty())
{
if (column.ColumnType == typeof(double))
{
var num = Double.Parse(val, NumberStyles.Number, column.RealColumnEdit.EditFormat.Format);
return new BinaryOperator(column.FieldName, num, type);
}
if (column.ColumnType == typeof(float))
{
var num = float.Parse(val, NumberStyles.Number, column.RealColumnEdit.EditFormat.Format);
return new BinaryOperator(column.FieldName, num, type);
}
else
{
var num = int.Parse(val, NumberStyles.Number, column.RealColumnEdit.EditFormat.Format);
return new BinaryOperator(column.FieldName, num, type);
}
}
// DateTime example:
// DateTime dt = DateTime.ParseExact(val, "d", column.RealColumnEdit.EditFormat.Format);
// return new BinaryOperator(column.FieldName, dt, type);
}
catch
{
return null;
}
}
}
//
// HERE IS WHERE I WANT TO ADD THE FUNCTIONALITY I'M SPEAKING OF
//
else if (column.FieldName == "SectionDisplayUnits")
{
try
{
if (!strVal.IsEmpty())
{
}
}
catch
{
return null;
}
}
return base.CreateAutoFilterCriterion(column, condition, _value, strVal);
}
我该怎么做呢?我想我想通过这样的调用来拆分每个字符串Split(...)
:cellString.Split(' - ')
. 然后我将从调用返回的每个字符串解析Split(...)
为一个数字,以便我可以使用不等式运算符。但我只是不确定如何去做。我能得到一些帮助吗?谢谢!
更新:
请查看此处,与我自己和知识渊博的 DevExpress 代表就此事进行更深入的讨论。我得到了很多帮助,我想与需要类似帮助的人分享这些知识。 链接在这里。