Hi,
I have a custom DataGridViewColumn which uses custom editing control to edit values of cells. The editing control shows up in a edited cell when I want to edit a cell :), and that works just as it should. The problem is that my editing control is much bigger than the cell itself - is there any way to show editing control outside/'above' the cell being edited? Thanks in adv.

Recommended Answers

All 4 Replies

Assuming you are passing the rectangle of the control being edited to the custom edit control, you should just need to adjust Rectangle.Location Property. Be sure to create a clone of the rectangle before changing the location so you don't modify the original.

Thanks for your reply DdoubleD! What I did (Isolved my problem partially already) was overriding the PositionEditingControl(...) method of the DataGridViewTextBoxCell:

class CustomCell : DataGridViewTextBoxCell
    {
        public override Type EditType
        {
            get
            {
                //CustomEditingControl is the editing control I want to appear for this cell when it is in 'edit mode'
                return typeof(CustomEditingControl);
            }
        }
        public override void PositionEditingControl(bool setLocation, bool setSize, System.Drawing.Rectangle cellBounds, System.Drawing.Rectangle cellClip, DataGridViewCellStyle cellStyle, bool singleVerticalBorderAdded, bool singleHorizontalBorderAdded, bool isFirstDisplayedColumn, bool isFirstDisplayedRow)
        {
           //Here I change position and size to fit the size of the editing control
            Control c = DataGridView.EditingControl;
            //size
            cellBounds.Height = c.Height;
            cellBounds.Width = c.Width;
            cellClip.Height = c.Height;
            cellClip.Width = c.Width;

            //position
            //move editing control down, so it shows below DataGridCell
            cellBounds.Y += this.Size.Height;
            cellClip.Y += this.Size.Height;

            base.PositionEditingControl(setLocation, setSize, cellBounds, cellClip, cellStyle, singleVerticalBorderAdded, singleHorizontalBorderAdded, isFirstDisplayedColumn, isFirstDisplayedRow);
        }
    }

But I do not quite understand /I came to this solution by trying different things/ why I need to change values of 'cellBounds' as well as 'cellClip' parameters (changing only one of those does not make the editing control visible 'above' the cell being edited). Anyone can explain me the meaning of those values and the difference between them? - the one MSDN provides doesn't make it clearer for me. Thanks.

Not sure that you need to change the clip region, but it could be related to the tab order of the form's controls because leave and focus events do not fire off always in that order, sometimes producing undesirable affects. Just mentioning it to be aware of because I ran into a similar issue with a floating textbox on a treeview control that would sometimes be hidden underneath the treeview caused by this.

For this to work I have to set both cellClip and cellBounds (why?;), but now it works and perhaps why doesn't matter. Thank you again DdoubleD!

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.