Exemple #1
0
        /// <summary>
        /// Change the mouse pointer to a hand when the mouse moves over the image
        /// </summary>
        /// <param name="e">The event arguments</param>
        protected override void OnMouseMove(DataGridViewCellMouseEventArgs e)
        {
            ImageListColumn owner   = base.OwningColumn as ImageListColumn;
            Rectangle       content = base.GetContentBounds(e.RowIndex);
            Cursor          newCursor;

            base.OnMouseMove(e);

            // Figure out if the mouse is actually over the image
            if (owner != null && owner.ImageList != null && !base.ReadOnly)
            {
                newCursor = owner.OriginalCursor;

                if (content.Contains(e.Location))
                {
                    newCursor = Cursors.Hand;
                }

                // Update the cursor if necessary
                if (newCursor != null && base.DataGridView != null && base.DataGridView.Cursor != newCursor)
                {
                    base.DataGridView.Cursor = newCursor;
                }
            }
        }
        //=====================================================================

        /// <summary>
        /// This is used to clone the column
        /// </summary>
        /// <returns>A clone of the column</returns>
        public override object Clone()
        {
            ImageListColumn clone = (ImageListColumn)base.Clone();
            clone.ImageList = images;
            clone.NullImage = this.NullImage;
            clone.NullImageIndex = this.NullImageIndex;
            clone.NewRowImageIndex = this.NewRowImageIndex;

            return clone;
        }
Exemple #3
0
        /// <summary>
        /// Change the mouse cursor back to the default when leaving the cell
        /// </summary>
        /// <param name="rowIndex">The row index of the cell</param>
        protected override void OnMouseLeave(int rowIndex)
        {
            ImageListColumn owner = base.OwningColumn as ImageListColumn;

            if (owner != null && base.DataGridView.Cursor != owner.OriginalCursor)
            {
                base.DataGridView.Cursor = owner.OriginalCursor;
            }

            base.OnMouseLeave(rowIndex);
        }
Exemple #4
0
        /// <summary>
        /// Gets the image to display in the cell
        /// </summary>
        /// <param name="value">The value to be use in determining the image</param>
        /// <param name="rowIndex">The index of the cell's parent row</param>
        /// <returns>The image that should be displayed in the cell</returns>
        protected override object GetCellImage(object value, int rowIndex)
        {
            // Use the image from the image list
            ImageListColumn owner     = base.OwningColumn as ImageListColumn;
            Image           cellImage = null;
            int             cellValue = -1;

            if (owner != null && owner.ImageList != null)
            {
                if (value is int)
                {
                    cellValue = (int)value;
                }
                else
                if (value is short)
                {
                    cellValue = (short)value;
                }
                else
                if (value is bool)
                {
                    cellValue = ((bool)value) ? 1 : 0;
                }

                // Let the user map the value to an index
                MapIndexEventArgs mapArgs = new MapIndexEventArgs(owner.Index, rowIndex, value, cellValue);
                owner.OnMapValueToIndex(mapArgs);
                cellValue = mapArgs.Index;

                if (cellValue < 0 || cellValue >= owner.ImageList.Images.Count)
                {
                    cellValue = owner.NullImageIndex;

                    if (cellValue >= owner.ImageList.Images.Count)
                    {
                        cellValue = -1;
                    }
                }

                if (cellValue != -1)
                {
                    cellImage = owner.ImageList.Images[cellValue];
                }
                else
                {
                    cellImage = owner.NullImage;
                }
            }

            return(cellImage);
        }
Exemple #5
0
        /// <summary>
        /// This is overridden to cycle through the image index values when the cell is clicked and the cell is
        /// editable.
        /// </summary>
        /// <param name="e">The event arguments</param>
        protected override void OnContentClick(DataGridViewCellEventArgs e)
        {
            ImageListColumn owner     = base.OwningColumn as ImageListColumn;
            int             cellValue = -1;
            object          newValue  = base.NewValue;

            if (!base.ReadOnly && base.DataGridView != null && owner != null && owner.ImageList != null)
            {
                if (newValue is int)
                {
                    cellValue = (int)newValue;
                }
                else
                if (newValue is short)
                {
                    cellValue = (short)newValue;
                }
                else
                if (newValue is bool)
                {
                    cellValue = ((bool)newValue) ? 1 : 0;
                }
                else
                if (newValue == null || newValue == DBNull.Value)
                {
                    cellValue = owner.NullImageIndex;
                }

                // Let the user map the value to an index
                MapIndexEventArgs mapArgs = new MapIndexEventArgs(e.ColumnIndex, e.RowIndex, newValue, cellValue);
                owner.OnMapValueToIndex(mapArgs);
                cellValue = mapArgs.Index + 1;

                // Cycle back to zero?
                if (cellValue < 0 || cellValue >= owner.ImageList.Images.Count)
                {
                    cellValue = 0;
                }

                // If set to the null image index, set it to null.  Otherwise, use the value.
                if (cellValue != owner.NullImageIndex)
                {
                    // Let the user map the index back to a value
                    mapArgs.Index = cellValue;
                    mapArgs.Value = cellValue;
                    owner.OnMapIndexToValue(mapArgs);

                    // If the value changed, use that.  If the value didn't change, use the new index value but
                    // convert it to the matching type.
                    if (mapArgs.Value == null || !mapArgs.Value.Equals(cellValue))
                    {
                        base.NewValue = mapArgs.Value;
                    }
                    else
                    if (newValue is int)
                    {
                        base.NewValue = cellValue;
                    }
                    else
                    if (newValue is short)
                    {
                        base.NewValue = (short)cellValue;
                    }
                    else
                    if (newValue is bool)
                    {
                        if (cellValue == 1)
                        {
                            base.NewValue = true;
                        }
                        else
                        {
                            base.NewValue = false;
                        }
                    }
                    else
                    {
                        base.NewValue = mapArgs.Value;
                    }
                }
                else
                {
                    base.NewValue = null;
                }

                base.DataGridView.NotifyCurrentCellDirty(true);
                base.DataGridView.InvalidateCell(this);
            }
        }