C# 如何将工具提示文本添加到数据列的标题


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

这是我代码的一部分。我的问题是如何在数据列的标题上添加工具提示文本?例如,在"否"或"日期"上添加工具提示文本...?

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

相关内容

  • 没有找到相关文章

最新更新