Вы всегда можете иметь StatusStrip
и с помощью событий CellMouseEnter
и CellMouseLeave
установить и удалить (соответственно) объяснение из строки состояния.
private void dgvCellMouseEnter(object sender, DataGridViewCellEventArgs e)
{
statusStrip1.Text = (sender as DataGridView)[e.ColumnIndex, e.RowIndex].ToolTipText;
}
private void dgvCellMouseLeave(object sender, DataGridViewCellEventArgs e)
{
statusStrip1.Text = "";
}
В качестве дополнительной функции вы можете показать, что в ячейке есть «дополнительная» информация, показывая небольшую отметку, например, в Excel. Вот небольшой фрагмент кода, который я использую, чтобы сделать то же самое:
private void dgvCellPainting(object sender, DataGridViewCellPaintingEventArgs e)
{
if (e.ColumnIndex != -1) && (e.RowIndex != -1)
{
DataGridViewCell dgvCell = (sender as DataGridView)[e.ColumnIndex, e.RowIndex];
Pen greenPen = new Pen(Color.Green, 2);
Boolean hasTooltip = !dgvCell.ToolTipText.Equals("");
Boolean hasCompleted = (dgvCell.Tag as CellInfo).complete; // CellInfo is a custom class
if (hasTooltip) && (hasCompleted)
{
e.Handled = true;
e.Paint(e.ClipBounds, e.PaintParts);
e.Graphics.DrawRectangle(Pens.Blue, e.CellBounds.Left + 5, e.CellBounds.Top + 2, e.CellBounds.Width - 12, e.CellBounds.Height - 6);
e.Graphics.DrawRectangle(greenPen, e.CellBounds.Left + 1, e.CellBounds.Top + 1, e.CellBounds.Width - 3, e.CellBounds.Height - 3);
}
else if (hasTooltip)
{
e.Handled = true;
e.Paint(e.ClipBounds, e.PaintParts);
e.Graphics.DrawRectangle(Pens.Blue, e.CellBounds.Left, e.CellBounds.Top, e.CellBounds.Width - 2, e.CellBounds.Height - 2);
}
else if (hasCompleted)
{
e.Handled = true;
e.Paint(e.ClipBounds, e.PaintParts);
e.Graphics.DrawRectangle(greenPen, e.CellBounds.Left + 1, e.CellBounds.Top + 1, e.CellBounds.Width - 3, e.CellBounds.Height - 3);
}
}
}
Этот код рисует синюю рамку вокруг ячейки, если hasTooltip
истинно, зеленую рамку, если hasCompleted
истина, и обе границы (с зеленой внутри), если оба истинны.