Add additional information as a popup in the DataGrid cell

How can I get additional information that appears from a cell in a DataGrid?

The grid column has a value of YES or NO . For NO values, I need to give an explanation of why it is NO . Is there something simple / obvious that can be done?

+7
c # winforms datagrid
source share
4 answers

You can always have a StatusStrip and with the help of the CellMouseEnter and CellMouseLeave events, an CellMouseLeave set and removed (respectively) from the status bar.

  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 = ""; } 

As an optional feature, you can show that the cell has โ€œextraโ€ information by showing a small mark, such as Excel. Here is a small piece of code that I use to do the same:

  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); } } } 

This code draws a blue border around the cell if hasTooltip is true, a green border if hasCompleted is true, and both borders (with green inside) if both are true.

+1
source share

Have you tried to attach a hint to the cell (conditionally)?

Set tooltip data in ItemDataBound (or dynamic <% # binding)

0
source share

Try using RowDetails; you can specify a RowDetailsTemplate to display detailed row information. You can see an example of Row data here .

0
source share

Have you tried ASP.NET AJAX PopupControl ? You can pop up on any control, and the popup is as simple as placing controls inside the panel, such as labels.

-one
source share

All Articles