Beispiel #1
0
        private void GridRowPrePaint(object sender, DataGridViewRowPrePaintEventArgs e)
        {
            var rowBounds = new Rectangle(
                RowHeadersWidth,
                e.RowBounds.Top,
                Columns.GetColumnsWidth(DataGridViewElementStates.Visible) - HorizontalScrollingOffset + 1,
                e.RowBounds.Height);

            int realIndex = _rowManager.RealIndex(e.RowIndex);

            if (FeatureSet.FeatureSelected(realIndex))
            {
                e.PaintParts &= ~DataGridViewPaintParts.Background;
                e.PaintHeader(false);
                e.Graphics.FillRectangle(new SolidBrush(_selectionColor), rowBounds);
            }
        }
Beispiel #2
0
        private void GridCellValueNeeded(object sender, DataGridViewCellValueEventArgs e)
        {
            int realIndex = RowManager.RealIndex(e.RowIndex);

            e.Value = _table.CellValue(e.ColumnIndex, realIndex);
        }
Beispiel #3
0
        private void GridCellValuePushed(object sender, DataGridViewCellValueEventArgs e)
        {
            var s = e.Value as string;

            int realIndex = RowManager.RealIndex(e.RowIndex);

            var fld = _table.Fields[e.ColumnIndex];

            if (s == null)
            {
                switch (fld.Type)
                {
                case AttributeType.String:
                    _table.EditCellValue(e.ColumnIndex, realIndex, string.Empty);
                    break;

                case AttributeType.Integer:
                    _table.EditCellValue(e.ColumnIndex, realIndex, 0);
                    break;

                case AttributeType.Double:
                    _table.EditCellValue(e.ColumnIndex, realIndex, 0.0);
                    break;

                case AttributeType.Boolean:
                    _table.EditCellValue(e.ColumnIndex, realIndex, false);
                    break;

                case AttributeType.Date:
                    _table.EditCellValue(e.ColumnIndex, realIndex, DateTime.MinValue);
                    break;
                }
            }
            else
            {
                switch (fld.Type)
                {
                case AttributeType.String:
                    if (fld.Width < s.Length)
                    {
                        MessageService.Current.Info("The string is too long and will be truncated.");
                        s = s.Substring(0, fld.Width);
                    }
                    _table.EditCellValue(e.ColumnIndex, realIndex, s);
                    break;

                case AttributeType.Integer:
                {
                    if (int.TryParse(s, out int val))
                    {
                        _table.EditCellValue(e.ColumnIndex, realIndex, val);
                    }
                    else
                    {
                        MessageService.Current.Info("The string is not recognized as an integer value.");
                    }
                }
                break;

                case AttributeType.Double:
                {
                    if (double.TryParse(s, out double val))
                    {
                        _table.EditCellValue(e.ColumnIndex, realIndex, val);
                    }
                    else
                    {
                        MessageService.Current.Info(
                            "The string is not recognized as a floating point numeric value.");
                    }
                }
                break;

                case AttributeType.Date:
                {
                    if (DateTime.TryParse(s, out DateTime val))
                    {
                        _table.EditCellValue(e.ColumnIndex, realIndex, val);
                    }
                    else
                    {
                        MessageService.Current.Info(
                            "The string is not recognized as a date/time value.");
                    }
                }
                break;

                case AttributeType.Boolean:
                {
                    if (bool.TryParse(s, out bool val))
                    {
                        _table.EditCellValue(e.ColumnIndex, realIndex, val);
                    }
                    else
                    {
                        MessageService.Current.Info(
                            "The string is not recognized as a boolean value.");
                    }
                }
                break;
                }
            }

            DelegateHelper.FireEvent(this, CellValueEdited);
        }