0

我正在尝试改进AutoFilterRow我的专栏之一的功能。该列将始终由一个字符串组成,该字符串表示一系列值,如下所示:"num1 - num2". 我想允许最终用户AutoFilterRow在该特定列中的单元格中键入一个值,并且其部分的范围包含他们键入的数字的行。例如,如果我有 3 行,并且它们的每个部分属性如下:"1 - 4""1 - 6"和,并且用户在此列的单元格中"4 - 6"键入,我希望行包含和。"3"AutoFilterRow"1 - 4""1 - 6"

我已经覆盖了CreateAutoFilterCriterioninMyGridView以允许附加运算符,如本网站上的几个示例中所建议的:

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 代表就此事进行更深入的讨论。我得到了很多帮助,我想与需要类似帮助的人分享这些知识。 链接在这里。

4

1 回答 1

1

使用 C#,您可以将值分成两部分,将它们转换为数字,并将用户输入的值与这两个值进行比较,以确保它大于或等于第一部分并且小于或等于第二部分。

标准语言中,可以使用函数运算符创建相同的功能。但是,表达式会有点复杂。请尝试以下方法。只有在 SectionDisplayUnits 列中的值格式是固定的并且该值总是由两个用“-”分隔的数字组成时,它才会起作用。

string rangeDelimiter = "-";
return CriteriaOperator.Parse("toint(trim(substring(SectionDisplayUnits, 0, charindex(?, SectionDisplayUnits)))) <= ? && toint(trim(substring(SectionDisplayUnits, charindex(?, SectionDisplayUnits) + 1, len(SectionDisplayUnits) - charIndex(?, SectionDisplayUnits) - 1))) >= ?", rangeDelimiter, _value, rangeDelimiter, rangeDelimiter, _value);
于 2014-06-02T09:48:11.837 回答