我想动态添加 Devexpress GridControl。在运行时我想显示过滤器行。另外,我希望在具有动态创建的 GridControl 的同一窗体上有一个按钮。单击该按钮时,它应该显示网格控件的过滤器对话框弹出窗口。
提供的示例可以满足您的要求。
- 创建一个名为 Form1 的表单。
- 创建一个名为button1的按钮并将其停靠到
表格的顶部。
using System;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using DevExpress.XtraGrid;
using DevExpress.XtraGrid.Views.Grid;
using DevExpress.XtraGrid.Columns;
namespace Samples
{
public partial class Form1 : Form
{
private GridControl grid;
private GridView view;
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
view.ShowFilterPopup(view.Columns[0]);
}
private void Form1_Load(object sender, EventArgs e)
{
grid = new GridControl();
view = new GridView();
grid.Dock = DockStyle.Fill;
grid.ViewCollection.Add(view);
grid.MainView = view;
view.GridControl = grid;
view.OptionsView.ShowAutoFilterRow = true;
GridColumn column = view.Columns.Add();
column.Caption = "Name";
column.FieldName = "Name";
column.Visible = true;
// The grid control requires at least one row
// otherwise the FilterPopup dialog will not show
DataTable table = new DataTable();
table.Columns.Add("Name");
table.Rows.Add("Hello");
table.Rows.Add("World");
grid.DataSource = table;
this.Controls.Add(grid);
grid.BringToFront();
}
}
}
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)