示例#1
0
        public void Initialize(MapEditorActionsSelectorVM vm)
        {
            _vm = vm;

            DGV.CurrentCellDirtyStateChanged += DGV_CurrentCellDirtyStateChanged;
            DGV.DataBindings.Add(nameof(DGV.CurrentRowIndex), _vm, nameof(_vm.SelectedIndex), false, DataSourceUpdateMode.OnPropertyChanged);
            SetupDataGridView(_vm);
        }
示例#2
0
        private void SetupDataGridView(MapEditorActionsSelectorVM vm)
        {
            DGV.DataSource = null;

            DGV.Columns.Clear();
            DGV.RowHeadersVisible     = false;
            DGV.AllowUserToAddRows    = false;
            DGV.AllowUserToDeleteRows = false;
            DGV.AllowUserToResizeRows = false;
            DGV.MultiSelect           = false;
            DGV.AutoGenerateColumns   = false;
            DGV.SelectionMode         = DataGridViewSelectionMode.FullRowSelect;
            DGV.RowTemplate.Height    = 32;

            DataGridViewCheckBoxColumn visibilityColumn = new DataGridViewCheckBoxColumn();

            visibilityColumn.HeaderText       = "Is visible";
            visibilityColumn.Name             = "IsVisible";
            visibilityColumn.DataPropertyName = "IsVisible";
            visibilityColumn.MinimumWidth     = 50;
            visibilityColumn.Width            = 50;
            visibilityColumn.Resizable        = DataGridViewTriState.False;
            DGV.Columns.Add(visibilityColumn);

            DataGridViewImageColumn presentationColumn = new DataGridViewImageColumn();

            presentationColumn.HeaderText                 = "Icon";
            presentationColumn.Name                       = "Icon";
            presentationColumn.DataPropertyName           = "Icon";
            presentationColumn.ImageLayout                = DataGridViewImageCellLayout.Normal;
            presentationColumn.DefaultCellStyle.BackColor = Color.Gray;
            presentationColumn.ReadOnly                   = true;
            presentationColumn.MinimumWidth               = 50;
            presentationColumn.Width                      = 50;
            presentationColumn.Resizable                  = DataGridViewTriState.False;
            DGV.Columns.Add(presentationColumn);

            DataGridViewTextBoxColumn idColumn = new DataGridViewTextBoxColumn();

            idColumn.HeaderText       = "Id";
            idColumn.Name             = "Id";
            idColumn.DataPropertyName = "Id";
            idColumn.MinimumWidth     = 40;
            idColumn.Width            = 40;
            idColumn.ReadOnly         = true;
            idColumn.Resizable        = DataGridViewTriState.False;
            DGV.Columns.Add(idColumn);

            DataGridViewTextBoxColumn descriptionColumn = new DataGridViewTextBoxColumn();

            descriptionColumn.HeaderText                = "Description";
            descriptionColumn.Name                      = "Description";
            descriptionColumn.DataPropertyName          = "Description";
            descriptionColumn.DefaultCellStyle.WrapMode = DataGridViewTriState.True;
            descriptionColumn.AutoSizeMode              = DataGridViewAutoSizeColumnMode.Fill;
            descriptionColumn.ReadOnly                  = true;
            descriptionColumn.Resizable                 = DataGridViewTriState.False;
            DGV.Columns.Add(descriptionColumn);

            DGV.DataSource = vm.Items;
        }