protected void PopulateReadingsGrid()
{
if (sd == null || sd.ReadingsCount == 0) return;
pb.Value1 = 0;
pb.Maximum = sd.ReadingsCount;
ToolTip toolTip1 = new ToolTip();
DataTable dt = new DataTable();
DataColumn dcIndex = new DataColumn("No");
DataColumn dcDate = new DataColumn("Date");
DataColumn dcTime = new DataColumn("Time");
DataColumn dcUnComp = new DataColumn("UnCompensated Height");
DataColumn dcCompHeight = new DataColumn(sd.isBarometric ? "Pressure" : "Compensated Height");
DataColumn dcWaterDepthBelowDatum = new DataColumn("Depth of Water Below Datum");
DataColumn dcTemperature = new DataColumn("Temperature");
dt.Columns.Add(dcIndex);
dt.Columns.Add(dcDate);
dt.Columns.Add(dcTime);
dt.Columns.Add(dcUnComp);
dt.Columns.Add(dcCompHeight);
dt.Columns.Add(dcWaterDepthBelowDatum);
dt.Columns.Add(dcTemperature);
}
那是我的代码的一部分。我的问题是如何在我的数据列的标题上添加工具提示文本?例如,在" No"上添加工具提示文字。或"日期" ......?
答案 0 :(得分:0)
private void dt_CellMouseDown(object sender, DataGridViewCellMouseEventArgs e)
{
if (e.ColumnIndex == -1)
{
// get text
string msg = (sender as DataGridView).Rows[e.RowIndex].Cells[e.ColumnIndex].Value;
// Get mouse position relative to the grid
var relativeMousePosition = dt.PointToClient(Cursor.Position);
// Show the tooltip
this.toolTip1.Show(msg, dt, relativeMousePosition);
}
}