5

Devexpress GridControl を動的に追加したい。実行時に、フィルター行を表示したいと考えています。また、動的に作成された GridControl を持つ同じフォームにボタンを配置したいと考えています。ボタンをクリックすると、グリッド コントロールのフィルター ダイアログ ポップアップが表示されます。

4

1 に答える 1

6

提供されたサンプルは、あなたが求めることを行います。

  • 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();
        }
    }
}

于 2009-12-10T15:47:40.390 に答える