将Devexpress GridControl动态添加到C#Windows应用程序 [英] Dynamically adding Devexpress GridControl to C# windows application

查看:46
本文介绍了将Devexpress GridControl动态添加到C#Windows应用程序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想动态添加Devexpress GridControl.在运行时,我想显示筛选器行".我也想在具有动态创建的GridControl的同一窗体上创建一个按钮.单击该按钮时,应显示网格控件的过滤器对话框"弹出窗口.

I want to add Devexpress GridControl dynamically. At runtime I want to show the Filter Row. Also I want to have a button on the same form that has the dynamically created GridControl. When the button is clicked it should show the Filter Dialog popup for the grid control.

推荐答案

所提供的示例满足您的要求.

The provided sample does what you ask for.

  • 创建一个名为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();
        }
    }
}

这篇关于将Devexpress GridControl动态添加到C#Windows应用程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆