DevExpress 获取gridview输入的查询筛选值

Posted 小飞鱼通达二开

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了DevExpress 获取gridview输入的查询筛选值相关的知识,希望对你有一定的参考价值。

在需要导出表格数据时需要,先获取输入的过滤值,可以通过以下代码获取:

            string shortNameSearchStr = "";
            //获取输入的过滤值
            if (gridView1.FocusedColumn.FieldName == "简称" )
               
                customerShortNameSearchStr = gridView1.Columns["简称"].FilterInfo.Value.ToString();
            

设置需要导出的内容

            string sql = "Select * from v2_order where 1=1";
            if (customerShortNameSearchStr!="")
            
                sql += " and 简称='"+shortNameSearchStr + "'";
            
            sql += " order by 业务日期, 提货Id";
            var dataTableCollection = new CommonData().GetDataSet( sql ).Tables;
            if (dataTableCollection != null)
            
                DataTable datasource = dataTableCollection[0];
                if (datasource == null)
                
                    XtraMessageBox.Show("无法导出数据,请检查");
                
                Export(datasource);
            

导出方法:


        public void Export(DataTable datasource)
        
            SaveFileDialog saveFileDialog = new SaveFileDialog();
            saveFileDialog.DefaultExt = "xls";
            saveFileDialog.Filter = "Excel文件|*.xls";

            string filename = "order_" + DateTime.Now.ToString("yyyyMMdd") + "_" + DateTime.Now.Hour.ToString() + "." +
                              DateTime.Now.Minute.ToString();
            saveFileDialog.FileName = filename;

            if (saveFileDialog.ShowDialog() == DialogResult.OK)
            
                GridControl grid = new GridControl();
                ;
                GridView view = new GridView();
                grid.ViewCollection.Add(view);
                grid.MainView = view;
                view.GridControl = grid;

                foreach (DataColumn dc in datasource.Columns)
                
                    GridColumn gridColumnNumber = view.Columns.AddVisible(dc.ColumnName);
                    gridColumnNumber.FieldName = dc.ColumnName;

                

                grid.DataSource = datasource;
                this.Controls.Add(grid);                            //重要  
                grid.ForceInitialize();                             //重要  


                view.BestFitColumns();
                
                view.HorzScrollVisibility = DevExpress.XtraGrid.Views.Base.ScrollVisibility.Always;
                view.OptionsPrint.AutoWidth = false;

                view.ExportToXls(saveFileDialog.FileName);
                XtraMessageBox.Show("导出成功");
            
        

以上是关于DevExpress 获取gridview输入的查询筛选值的主要内容,如果未能解决你的问题,请参考以下文章

DevExpress 获取gridview输入的查询筛选值

DevExpress 获取gridview 鼠标位置所在单元格

DevExpress GridView获取选中行某列的值

devexpress gridview 中选择多行 剪切,粘帖功能怎么做?

devexpress的Gridview控件,如何获取Gridview DataItemTemplate中定义的控件的焦点???

关于怎样获取DevExpress GridView过滤后或排序后的数据集问题(转)