Hi all,
I have extended the
DataGridView
to have more features than the default control. I have added a feature that shows a
PictureBox
with an icon if a cell cannot display all it's contents. If the icon is clicked it changes the wrap-mode of the owning row and changes the
AutoSizeRowsMode
to displayed-cells.
I'm showing this icon by listening to the
CellMouseEnter
event and then calculating the rectangle to place the icon in the bottom right corner of the cell as follows:
if ((e.RowIndex < 0) || (e.ColumnIndex < 0))
{
_pbExpand.Visible = false;
return;
}
DataGridViewCell CellToUse = this[e.ColumnIndex, e.RowIndex];
if (CellToUse.Size.Width < CellToUse.PreferredSize.Width)
{
Rectangle DisplayRect = this.GetCellDisplayRectangle(e.ColumnIndex,
e.RowIndex, false);
_pbExpand.Location = new Point(DisplayRect.Right -
_pbExpand.Image.Width, DisplayRect.Bottom - _pbExpand.Image.Height);
_pbExpand.Tag = CellToUse;
_pbExpand.Visible = true;
_pbExpand.Image = (CellToUse.OwningRow.DefaultCellStyle.WrapMode ==
DataGridViewTriState.True) ? Resources.chevron_icon :
Resources.chevron_expand_icon;
}
My problem comes after the row has been expanded and the mouse pointer leaves the cell and enters again later. It ignores the
PictureBox
(it's still drawn to the correct place). If I hold the mouse pointer over the
PictureBox
then it fires the
CellMouseEnter
event hundreds of times instead of firing the
MouseEnter
event for the
PictureBox
. It works perfectly fine if the row is expanded and the pointer never leaves the cell. If anyone can point me in the right direction I would appreciate it.
Edit: It only seems to happen when the
DataGridView
property
AutoSizeRowsMode
is set to DisplayedCells. It also seems to happen only when there is a control on the cell & the mouse pointer enters that control.