Problem about showing ErrorIcon and Error tooltip text in the dgv.
Hey all,
I tried to show both error Icon and error tooltrip text when the error
is raised.
The cell ErrorText is set in the CellValidating event handler function
in my dgv like followings,
if (Convert.ToInt64(e.FormattedValue.ToString()) > 65535)
{
_cell.ErrorText = "65,535 error!";
_cellErrorAppears = true;
}
if (_cellErrorAppears)
{
if (_cell.Tag == null)
{
_cell.Tag = _cell.Style.Padding;
_cell.Style.Padding = new Padding(0, 0,
25, 0);
cellInError = new Point(e.ColumnIndex,
e.RowIndex);
}
if (errorTooltip == null)
{
errorTooltip = new ToolTip();
errorTooltip.InitialDelay = 0;
errorTooltip.ReshowDelay = 0;
errorTooltip.Active = false;
}
e.Cancel = true;
In dgv_CellPainting event handler, the error icon is depicted by the
following,
if (dgv.IsCurrentCellDirty && !String.IsNullOrEmpty(e.ErrorText))
{
// paint everything except error icon
e.Paint(e.ClipBounds, DataGridViewPaintParts.All &
~(DataGridViewPaintParts.ErrorIcon));
// now move error icon over to fill in the padding
space
GraphicsContainer container =
e.Graphics.BeginContainer();
e.Graphics.TranslateTransform(18, 0);
e.Paint(this.ClientRectangle,
DataGridViewPaintParts.ErrorIcon);
e.Graphics.EndContainer(container);
e.Handled = true;
}
When the mouse move to the cell, the error tooltrip should show
itself. However, it doesn't. Moreover, when the cell is edited once
more with the wrong input, the error Icon disappear as well.
In dgv_CellMouseMove()
{
if (cellInError.X == e.ColumnIndex &&
cellInError.Y == e.RowIndex)
{
DataGridViewCell _cell = dgv[e.ColumnIndex,
e.RowIndex];
if (_cell.ErrorText != String.Empty)
{
if (!errorTooltip.Active)
{
errorTooltip.Show(_cell.ErrorText, dvg, 1000);
}
errorTooltip.Active = true;
}
}
}
In dgv_CellMouseLeave()
{
DataGridViewCell _cell = dgv[e.ColumnIndex, e.RowIndex];
Font regularFont = new Font(dgv.Font, FontStyle.Regular);
_cell.Style.Font = regularFont;
}
The code in the CellEndEdit event handler is as follows,
dgv_CellEndEdit()
{
if (dgv[e.ColumnIndex, e.RowIndex].ErrorText != String.Empty)
{
DataGridViewCell _cell = dgv[e.ColumnIndex,
e.RowIndex];
_cell.ErrorText = String.Empty;
cellInError = new Point(-2, -2);
_cell.Style.Padding = (Padding)_cell.Tag;
if (errorTooltip != null)
{
errorTooltip.Hide(dgv);
errorTooltip.Dispose();
errorTooltip = null;
}
}
}
Can anyone give me a hand with this problem?
Thanks in advance.
Date:Sun, 05 Aug 2007 17:38:33 -0000
Author:
|