VirtualModel数据填充排序与筛选

    private void sgc1_LoadVirtualRow(object sender, DevComponents.DotNetBar.SuperGrid.GridVirtualRowEventArgs e)
    {
        //排序
        try
        {
            GridPanel sgc1gridpanel = e.GridPanel;
            foreach (var column in sgc1gridpanel.SortColumns)
            {
                if (column.SortDirection==DevComponents.DotNetBar.SuperGrid.SortDirection.Ascending)
                {
                    dv.Sort = column.Name + " desc";
                }
                else
                {
                    dv.Sort = column.Name + " asc";
                }
            }
            DT = dv.Table;
        }
        catch (Exception r)
        {
            return;
        }
        //数据填充
        try
        {
            using (DevComponents.DotNetBar.SuperGrid.GridRow row = e.GridRow)
                for (int i = 0; i < DT.Columns.Count; i++)
                {
                    row.Cells[i].Value = dv[row.Index][i];
                }
        }
        catch (Exception r)
        {
            return;
        }

    }

    /// <summary>
    /// 数据筛选
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    private void sgc1_FilterEditValueChanged(object sender, DevComponents.DotNetBar.SuperGrid.GridFilterEditValueChangedEventArgs e)
    {
        try
        {
            string s_where = "";
            GridPanel sgc1panel = sgc1.PrimaryGrid;
            string ls_columname1 = "";

            //遍历所有筛选栏
            foreach (GridColumn column in sgc1panel.Columns)
            {
                int li_co_in = column.ColumnIndex;
                string ls_columname = column.Name;

                //当前操作栏位需获取编辑后数据,因此单独列出
                if (column == e.GridColumn)
                {
                    if (e.NewExpr != null)
                    {
                        ls_columname1 = (string)e.NewValue;
                        if (DT.Columns[column.ColumnIndex].DataType == Type.GetType("System.Int") || DT.Columns[column.ColumnIndex].DataType == Type.GetType("System.Int16") || DT.Columns[column.ColumnIndex].DataType == Type.GetType("System.Int32") || DT.Columns[column.ColumnIndex].DataType == Type.GetType("System.Decimal") || DT.Columns[column.ColumnIndex].DataType == Type.GetType("System.Long"))
                        {
                            s_where += " and " + ls_columname + " = " + "" + ls_columname1 + "";
                        }
                        else
                        {
                            s_where += " and " + ls_columname + " like " + "'%" + ls_columname1 + "%'";
                        }
                    }
                }

                //其余栏位获取历史数据即可
                else
                {
                    if (column.FilterExpr != null)
                    {
                        ls_columname1 = (string)column.FilterValue;
                        if (DT.Columns[column.ColumnIndex].DataType == Type.GetType("System.Int") || DT.Columns[column.ColumnIndex].DataType == Type.GetType("System.Int16") || DT.Columns[column.ColumnIndex].DataType == Type.GetType("System.Int32") || DT.Columns[column.ColumnIndex].DataType == Type.GetType("System.Decimal") || DT.Columns[column.ColumnIndex].DataType == Type.GetType("System.Long"))
                        {
                            s_where += " and " + ls_columname + " = " + "" + ls_columname1 + "";
                        }
                        else
                        {
                            s_where += " and " + ls_columname + " like " + "'%" + ls_columname1 + "%'";
                        }
                    }
                }
            }
            dv = DT.DefaultView;
            dv.RowFilter = "1=1" + s_where;
            this.sgc1.PrimaryGrid.Rows.Clear();
            this.sgc1.PrimaryGrid.VirtualRowCount = dv.Count;
        }
        catch (Exception r)
        {
            return;
        }
    }
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

慕枫枫1120

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值