Пример #1
0
        public override void InitializeEditingControl(int rowIndex, object
                                                      initialFormattedValue, DataGridViewCellStyle dataGridViewCellStyle)
        {
            // Set the value of the editing control to the current cell value.
            base.InitializeEditingControl(rowIndex, initialFormattedValue,
                                          dataGridViewCellStyle);
            Reportman.Reporting.Variant nvalue = (Variant)GetColumnValue("VALUE", rowIndex);
            ObjectInspectorCellType     ntype  = (ObjectInspectorCellType)GetColumnValue("TYPEENUM", rowIndex);

            if (ntype == ObjectInspectorCellType.Image)
            {
                nvalue = (Variant)GetColumnValue("VALUEBIN", rowIndex);
            }

            if (DataGridView.EditingControl is DataGridViewComboBoxEditingControl)
            {
                ComboBoxPicker = DataGridView.EditingControl as DataGridViewComboBoxEditingControl;
                Strings list = (Strings)GetColumnValue("VALUELIST", rowIndex);
                ComboBoxPicker.Items.Clear();
                foreach (string s in list)
                {
                    ComboBoxPicker.Items.Add(s);
                }
                if (ntype == ObjectInspectorCellType.DropDown)
                {
                    ComboBoxPicker.DropDownStyle = ComboBoxStyle.DropDown;

                    ComboBoxPicker.Text = nvalue.ToString();
                }
                else
                {
                    ComboBoxPicker.DropDownStyle = ComboBoxStyle.DropDownList;

                    if (!(nvalue.IsNull))
                    {
                        int index = -1;
                        if (nvalue.IsString())
                        {
                            index = ComboBoxPicker.Items.IndexOf(nvalue.ToString());
                        }
                        else
                        {
                            index = nvalue;
                        }

                        if ((index < ComboBoxPicker.Items.Count) && (index >= 0))
                        {
                            ComboBoxPicker.SelectedIndex = index;
                        }
                        else
                        {
                            ComboBoxPicker.SelectedIndex = -1;
                        }
                    }
                    else
                    {
                        ComboBoxPicker.SelectedIndex = -1;
                    }
                }
            }
            else
            if (DataGridView.EditingControl is DataGridViewTextBoxEditingControl)
            {
                TextBoxPicker = DataGridView.EditingControl as DataGridViewTextBoxEditingControl;
                switch (ntype)
                {
                case ObjectInspectorCellType.FontStyle:
                    TextBoxPicker.ReadOnly  = true;
                    TextBoxPicker.BackColor = SystemColors.Info;
                    TextBoxPicker.ForeColor = SystemColors.InfoText;
                    TextBoxPicker.Click    += ClickFontStyleEvent;
                    TextBoxPicker.Text      = GraphicUtils.StringFontStyleFromInteger((int)nvalue);
                    break;

                default:
                    TextBoxPicker.Text = nvalue.ToString();
                    break;
                }
            }
            else
            if (DataGridView.EditingControl is PanelColorPicker)
            {
                ColorPickerc = DataGridView.EditingControl as PanelColorPicker;
                if (nvalue.IsNull)
                {
                    ColorPickerc.TextDisplayed = false;
                    ColorPickerc.Color         = Color.White;
                }
                else
                {
                    ColorPickerc.TextDisplayed = true;
                    ColorPickerc.Color         = GraphicUtils.ColorFromInteger(nvalue);
                }
            }
            else
            if (DataGridView.EditingControl is PanelImagePicker)
            {
                ImagePickerc      = DataGridView.EditingControl as PanelImagePicker;
                ImagePickerc.xrow = ((DataRowView)DataGridView.Rows[rowIndex].DataBoundItem).Row;
                if (nvalue.IsNull)
                {
                    ImagePickerc.MemStream = new System.IO.MemoryStream();
                }
                else
                {
                    ImagePickerc.MemStream = nvalue.GetStream();
                }
            }
            else
            if (DataGridView.EditingControl is CheckBoxPickerControl)
            {
                CheckBoxPicker = DataGridView.EditingControl as CheckBoxPickerControl;
                if (nvalue.IsNull)
                {
                    CheckBoxPicker.CheckState = CheckState.Indeterminate;
                }
                else
                {
                    CheckBoxPicker.Checked = (bool)nvalue;
                }
            }
            else
            if (DataGridView.EditingControl is EllipsisEditingControl)
            {
                EllipsisPicker      = DataGridView.EditingControl as EllipsisEditingControl;
                EllipsisPicker.Text = nvalue.ToString();
                switch (ntype)
                {
                case ObjectInspectorCellType.FontName:
                    EllipsisPicker.ButtonClick += ClickFontNameEvent;
                    break;
                }
            }
            else
            if (DataGridView.EditingControl is NumericUpDownPickerControl)
            {
                NumericPicker = DataGridView.EditingControl as NumericUpDownPickerControl;
                switch (ntype)
                {
                case ObjectInspectorCellType.Decimal:
                    NumericPicker.DataType = TextBoxDataType.Numeric;
                    break;

                case ObjectInspectorCellType.Integer:
                    NumericPicker.DataType = TextBoxDataType.Integer;
                    break;
                }
                if (nvalue.IsNull)
                {
                    NumericPicker.Text = "";
                }
                else
                {
                    switch (ntype)
                    {
                    case ObjectInspectorCellType.Decimal:
                        NumericPicker.Text = ((decimal)nvalue).ToString("##0.0000");
                        break;

                    case ObjectInspectorCellType.Integer:
                        NumericPicker.Text = nvalue.ToString();
                        break;
                    }
                }
            }
        }
Пример #2
0
        protected override void Paint(Graphics graphics,
                                      Rectangle clipBounds, Rectangle cellBounds, int rowIndex,
                                      DataGridViewElementStates elementState, object value,
                                      object formattedValue, string errorText,
                                      DataGridViewCellStyle cellStyle,
                                      DataGridViewAdvancedBorderStyle advancedBorderStyle,
                                      DataGridViewPaintParts paintParts)
        {
            //            formattedValue = null;
            bool    painted = false;
            Variant nvalue  = (Variant)GetColumnValue("VALUE", rowIndex);

            if (!nvalue.IsNull)
            {
                ObjectInspectorCellType celltype = (ObjectInspectorCellType)GetColumnValue("TYPEENUM", rowIndex);
                if (celltype == ObjectInspectorCellType.Image)
                {
                    nvalue = (Variant)GetColumnValue("VALUEBIN", rowIndex);
                }
                switch (celltype)
                {
                case ObjectInspectorCellType.DropDownList:
                case ObjectInspectorCellType.DropDown:
                    Strings list  = (Strings)GetColumnValue("VALUELIST", rowIndex);
                    int     index = -1;
                    if (nvalue.IsString())
                    {
                        index = list.IndexOf(nvalue);
                    }
                    else
                    {
                        index = nvalue;
                    }
                    if (index < list.Count)
                    {
                        if (index >= 0)
                        {
                            formattedValue = list[index];
                        }
                        else
                        {
                            formattedValue = "";
                        }
                    }
                    break;

                case ObjectInspectorCellType.Text:
                    break;

                case ObjectInspectorCellType.Decimal:
                    Decimal dvalue = nvalue;
                    formattedValue = dvalue.ToString("##,##0.000");
                    break;

                case ObjectInspectorCellType.Integer:
                    Decimal ivalue = nvalue;
                    formattedValue = ivalue.ToString("##,##0");
                    break;

                case ObjectInspectorCellType.Color:
                    Color c = GraphicUtils.ColorFromInteger(nvalue);
                    formattedValue      = c.Name;
                    cellStyle.BackColor = c;
                    cellStyle.ForeColor = GraphicUtils.GetInvertedBlackWhite(c);
                    break;

                case ObjectInspectorCellType.Image:
                    System.IO.MemoryStream memstream = nvalue.GetStream();
                    formattedValue = StringUtil.GetSizeAsString(memstream.Length);
                    break;

                case ObjectInspectorCellType.FontStyle:
                    formattedValue      = GraphicUtils.StringFontStyleFromInteger(nvalue);
                    cellStyle.BackColor = SystemColors.Info;
                    cellStyle.ForeColor = SystemColors.InfoText;
                    break;

                case ObjectInspectorCellType.Boolean:
                    bool        boolvalue = (bool)nvalue;
                    ButtonState nstate;
                    if (boolvalue)
                    {
                        nstate = ButtonState.Checked;
                    }
                    else
                    {
                        nstate = ButtonState.Normal;
                    }
                    base.Paint(graphics, clipBounds, cellBounds, rowIndex, elementState, "", "",
                               "", cellStyle, advancedBorderStyle, paintParts);
                    // Make square cell Bounds
//                        int checkwidth=(int)Math.Round((double)cellStyle.Font.Size*(double)96/(double)72);
                    int checkwidth = 13;
                    int x1         = cellBounds.Left;
                    int y1         = cellBounds.Top;
                    int width1     = cellBounds.Width;
                    int height1    = cellBounds.Height;
                    if (height1 > width1)
                    {
                        y1      = height1 - (checkwidth / 2);
                        height1 = width1;
                    }
                    else
                    {
                        x1     = x1 + width1 / 2 - (checkwidth / 2);
                        y1     = y1 + (height1 - checkwidth) / 2;
                        width1 = height1;
                    }
                    Rectangle nbounds = new Rectangle(x1, y1, checkwidth, checkwidth);
                    ControlPaint.DrawCheckBox(graphics, nbounds, nstate);
                    painted = true;
                    break;
                }
            }
            if (!painted)
            {
                base.Paint(graphics, clipBounds, cellBounds, rowIndex, elementState, value, formattedValue,
                           errorText, cellStyle, advancedBorderStyle, paintParts);
            }


            /*           Rectangle ColorBoxRect = new Rectangle();
             *         RectangleF TextBoxRect = new RectangleF();
             *         GetDisplayLayout(cellBounds, ref ColorBoxRect, ref TextBoxRect);
             *
             *         //// Draw the cell background, if specified.
             *         if ((paintParts & DataGridViewPaintParts.Background) ==
             *             DataGridViewPaintParts.Background)
             *         {
             *             SolidBrush cellBackground;
             *             if (value != null && value.GetType() == typeof(Color))
             *             {
             *                 cellBackground = new SolidBrush((Color)value);
             *             }
             *             else
             *             {
             *                 cellBackground = new SolidBrush(cellStyle.BackColor);
             *             }
             *             graphics.FillRectangle(cellBackground, ColorBoxRect);
             *             graphics.DrawRectangle(Pens.Black, ColorBoxRect);
             *             Color lclcolor = (Color)value;
             *             graphics.DrawString(lclcolor.Name.ToString(), cellStyle.Font, System.Drawing.Brushes.Black, TextBoxRect);
             *
             *             cellBackground.Dispose();
             *         }*/
        }