1

我有一个绑定到 bindingSource 的 xtraGrid 控件(v12.1),最后从 LINQ 到实体查询(EF4.3.1)获取其数据,最终用户可以过滤和排序 gridView,我有一个 Stimulsoft 报告,显示当用户单击 PrintListButton 时 gridView 的内容,如何获取 xtragrid 过滤和排序的数据源,以便将其附加到报告中?谢谢。

4

1 回答 1

1
var data = GetDataView(xtraGridControl1);
report.RegData("List", data.ToTable());


        public DataView GetDataView(GridControl gc)
        {
            DataView dv = null;

            if (gc.FocusedView != null && gc.FocusedView.DataSource != null)
            {
                var view = (ColumnView)gc.FocusedView;
                var currentList = listBindingSource.List.CopyToDataTable().DefaultView; //(DataView)

                var filterExpression = GetFilterExpression(view);
                var sortExpression = GetSortExpression(view);

                var currentFilter = currentList.RowFilter;

                //create a new data view 
                dv = new DataView(currentList.Table) {Sort = sortExpression};

                if (filterExpression != String.Empty)
                {
                    if (currentFilter != String.Empty)
                    {
                        currentFilter += " AND ";
                    }
                    currentFilter += filterExpression;
                }
                dv.RowFilter = currentFilter;
            }
            return dv;
        }

        public string GetFilterExpression(ColumnView view)
        {
            var expression = String.Empty;

            if (view.ActiveFilter != null && view.ActiveFilterEnabled
                          && view.ActiveFilter.Expression != String.Empty)
            {
                expression = view.ActiveFilter.Expression;
            }
            return expression;
        }

        public string GetSortExpression(ColumnView view)
        {
            var expression = String.Empty;
            foreach (GridColumnSortInfo info in view.SortInfo)
            {
                expression += string.Format("[{0}]", info.Column.FieldName);

                if (info.SortOrder == DevExpress.Data.ColumnSortOrder.Descending)
                    expression += " DESC";
                else
                    expression += " ASC";
                expression += ", ";
            }
            return expression.TrimEnd(',', ' ');
        }
于 2012-06-27T15:27:35.163 回答