예제 #1
0
        public DgvUI()
        {
            InitializeComponent();

            // Grid data
            m_bs = new BindingSource <Record> {
                DataSource = new BindingListEx <Record>()
            };
            for (int i = 0; i != 10; ++i)
            {
                m_bs.Add(new Record("Name" + i, i, (EOptions)(i % 3)));
            }

            // Drag drop
            m_dd              = new DragDrop(m_grid);
            m_dd.DoDrop      += DataGridView_.DragDrop_DoDropMoveRow;
            m_grid.MouseDown += DataGridView_.DragDrop_DragRow;

            // log list
            m_events.ContextMenuStrip = new ContextMenuStrip();
            m_events.ContextMenuStrip.Items.Add2("Log DGV events", null, (s, a) =>
            {
                m_grid.List = m_grid.List == null ? m_events : null;
                ((ToolStripMenuItem)s).Checked = m_grid.List != null;
            });

            m_grid.AllowDrop             = true;
            m_grid.AutoGenerateColumns   = false;
            m_grid.AllowUserToAddRows    = true;
            m_grid.AllowUserToDeleteRows = true;
            m_grid.SelectionMode         = DataGridViewSelectionMode.FullRowSelect;
            m_grid.Columns.Add(new DataGridViewTextBoxColumn
            {
                Name             = "Name",
                DataPropertyName = nameof(Record.Name),
            });
            m_grid.Columns.Add(new DataGridViewTextBoxColumn
            {
                Name             = "Value",
                DataPropertyName = nameof(Record.Value),
            });
            m_grid.Columns.Add(new DataGridViewComboBoxColumn
            {
                Name             = "Option",
                DataPropertyName = nameof(Record.Option),
                FlatStyle        = System.Windows.Forms.FlatStyle.Flat,
                DataSource       = Enum <EOptions> .Values,
            });
            m_grid.Columns.Add(new DataGridViewTextBoxColumn
            {
                Name             = "FValue",
                DataPropertyName = nameof(Record.FValue),
            });
            m_grid.Columns.Add(new DataGridViewCheckMarkColumn
            {
                Name             = "CheckMark",
                DataPropertyName = nameof(Record.Checked),
            });
            m_grid.Columns.Add(new DataGridViewTrackBarColumn
            {
                Name             = "TrackBar",
                DataPropertyName = nameof(Record.Value),
                MinValue         = 0,
                MaxValue         = 100,
            });

            // Bind to the data source
            //m_grid.DataSource = new Record[0];
            m_grid.DataSource = m_bs;

            // Automatic column sizing
            m_grid.SizeChanged            += DataGridView_.FitColumnsToDisplayWidth;
            m_grid.ColumnWidthChanged     += DataGridView_.FitColumnsToDisplayWidth;
            m_grid.RowHeadersWidthChanged += DataGridView_.FitColumnsToDisplayWidth;
            m_grid.SetGridColumnSizes(DataGridView_.EColumnSizeOptions.FitToDisplayWidth);

            // Column filtering
            m_grid.ColumnFilters(true);
            m_grid.KeyDown += DataGridView_.ColumnFilters;
        }