private void subscribeToExternalUpdateEvents()
 {
     for (int i = 0; i < cells.Count; i++)
     {
         DataGridViewCell cell = cells[i];
         CustomDataGridViewColumnDescriptor <T> columnDescriptor = table.ColumnDescriptors[i];
         columnDescriptor.ExternalUpdateEventSubscriberMethod?.Invoke(item, () => columnDescriptor.UpdaterMethod?.Invoke(item, cell));
     }
 }
Beispiel #2
0
        public void AddColumn(CustomDataGridViewColumnDescriptor <T> columnDescriptor)
        {
            columnDescriptors.Add(columnDescriptor);
            DataGridViewColumn column = getColumnByType(columnDescriptor.Type);

            column.HeaderText   = columnDescriptor.Header;
            column.Width        = columnDescriptor.Width + columnDescriptor.DividerWidth;
            column.DividerWidth = columnDescriptor.DividerWidth;
            if (columnDescriptor.CellStyle != null)
            {
                column.DefaultCellStyle = columnDescriptor.CellStyle;
            }
            column.HeaderCell.Style.Alignment = DataGridViewContentAlignment.MiddleLeft;
            Columns.Add(column);
        }
        private void notifyMultilevelPropertyChangedHandler(string fullPropertyName, MultilevelPropertyChangeObserver observer)
        {
            object[] tagData = observer.Tag as object[];
            if ((tagData == null) || (tagData.Length != 2))
            {
                return;
            }
            DataGridViewCell cell = tagData[0] as DataGridViewCell;
            CustomDataGridViewColumnDescriptor <T> columnDescriptor = tagData[1] as CustomDataGridViewColumnDescriptor <T>;

            if (cell == null)
            {
                return;
            }
            columnDescriptor.UpdaterMethod?.Invoke(item, cell);
        }
        private void subscribeToMultilevelItemEvents()
        {
            INotifyPropertyChanged itemCastedINotifyPropertyChanged = item as INotifyPropertyChanged;

            if (itemCastedINotifyPropertyChanged == null)
            {
                return;
            }
            for (int i = 0; i < cells.Count; i++)
            {
                DataGridViewCell cell = cells[i];
                CustomDataGridViewColumnDescriptor <T> columnDescriptor = table.ColumnDescriptors[i];
                foreach (string[] eventNames in columnDescriptor.MultilevelChangeEvents)
                {
                    object[] tagData = new object[] { cell, columnDescriptor };
                    MultilevelPropertyChangeObserver multilevelObserver = new MultilevelPropertyChangeObserver(itemCastedINotifyPropertyChanged, eventNames, tagData);
                    multilevelObserver.MultilevelPropertyChanged += notifyMultilevelPropertyChangedHandler;
                }
            }
        }
        private DataGridViewCell createAndInitCell(CustomDataGridViewColumnDescriptor <T> columnDescriptor)
        {
            DataGridViewCell cell = getCellByType(columnDescriptor.Type);

            if (columnDescriptor.Type == DataGridViewColumnType.CheckBox)
            {
                DataGridViewCheckBoxCell typedCell = (DataGridViewCheckBoxCell)cell;
                typedCell.FalseValue = false;
                typedCell.TrueValue  = true;
            }

            if (columnDescriptor.Type == DataGridViewColumnType.Image)
            {
                DataGridViewImageCell typedCell = (DataGridViewImageCell)cell;
                typedCell.ImageLayout     = DataGridViewImageCellLayout.Zoom;
                typedCell.Style.Alignment = DataGridViewContentAlignment.MiddleCenter;
            }

            if (columnDescriptor.Type == DataGridViewColumnType.ImageButton)
            {
                DataGridViewImageButtonCell typedCell = (DataGridViewImageButtonCell)cell;
                typedCell.Image        = columnDescriptor.ButtonImage;
                typedCell.ImagePadding = columnDescriptor.ButtonImagePadding;
            }

            if (columnDescriptor.Type == DataGridViewColumnType.SmallIcon)
            {
                DataGridViewSmallIconCell typedCell = (DataGridViewSmallIconCell)cell;
                typedCell.IconShown   = columnDescriptor.IconShown;
                typedCell.IconColor   = columnDescriptor.IconColor;
                typedCell.IconType    = columnDescriptor.IconType;
                typedCell.IconPadding = columnDescriptor.IconPadding;
            }

            if (columnDescriptor.Type == DataGridViewColumnType.Button)
            {
                cell.Value = columnDescriptor.ButtonText;
            }

            if (columnDescriptor.Type == DataGridViewColumnType.DisableButton)
            {
                cell.Value = columnDescriptor.ButtonText;
            }

            if (columnDescriptor.Type == DataGridViewColumnType.ComboBox)
            {
                DataGridViewComboBoxCell typedCell = (DataGridViewComboBoxCell)cell;
                typedCell.DisplayStyle  = DataGridViewComboBoxDisplayStyle.DropDownButton;
                typedCell.ValueMember   = "Value";
                typedCell.DisplayMember = "Label";
                typedCell.Items.AddRange(columnDescriptor.DropDownPopulatorMethod?.Invoke(item, cell));
            }

            Cells.Add(cell);

            if (columnDescriptor.Type == DataGridViewColumnType.TextBox)
            {
                cell.ReadOnly = !columnDescriptor.TextEditable;
            }

            if (columnDescriptor.Type == DataGridViewColumnType.SmallIcon)
            {
                cell.ReadOnly = true;
            }

            columnDescriptor.InitializerMethod?.Invoke(item, cell);
            columnDescriptor.UpdaterMethod?.Invoke(item, cell);

            return(cell);
        }
Beispiel #6
0
 public CustomDataGridViewColumnDescriptorBuilder <T> ExternalUpdateEventSubscriberMethod(CustomDataGridViewColumnDescriptor <T> .ExternalUpdateEventSubscriberMethodDelegate externalUpdateEventSubscriberMethod)
 {
     this.externalUpdateEventSubscriberMethod = externalUpdateEventSubscriberMethod;
     return(this);
 }
Beispiel #7
0
 public CustomDataGridViewColumnDescriptorBuilder <T> CellEndEditHandlerMethod(CustomDataGridViewColumnDescriptor <T> .CellEndEditHandlerMethodDelegate endEditHandlerMethod)
 {
     this.endEditHandlerMethod = endEditHandlerMethod;
     return(this);
 }
Beispiel #8
0
 public CustomDataGridViewColumnDescriptorBuilder <T> CellDoubleClickHandlerMethod(CustomDataGridViewColumnDescriptor <T> .CellDoubleClickHandlerMethodDelegate contentDoubleClickHandlerMethod)
 {
     this.doubleClickHandlerMethod = contentDoubleClickHandlerMethod;
     return(this);
 }
Beispiel #9
0
 public CustomDataGridViewColumnDescriptorBuilder <T> DropDownPopulatorMethod(CustomDataGridViewColumnDescriptor <T> .CellDropDownPopulatorMethodDelegate dropDownPopulatorMethod)
 {
     this.dropDownPopulatorMethod = dropDownPopulatorMethod;
     return(this);
 }
Beispiel #10
0
 public CustomDataGridViewColumnDescriptorBuilder <T> UpdaterMethod(CustomDataGridViewColumnDescriptor <T> .CellUpdaterMethodDelegate updaterMethod)
 {
     this.updaterMethod = updaterMethod;
     return(this);
 }
Beispiel #11
0
 public CustomDataGridViewColumnDescriptorBuilder <T> InitializerMethod(CustomDataGridViewColumnDescriptor <T> .CellInitializerMethodDelegate initializerMethod)
 {
     this.initializerMethod = initializerMethod;
     return(this);
 }