C# 为自动创建的DataGridView列设置工具提示

C# 为自动创建的DataGridView列设置工具提示,c#,wpf,datagridview,tooltip,autogeneratecolumn,C#,Wpf,Datagridview,Tooltip,Autogeneratecolumn,我想通过编程将工具提示设置为DataGridView中自动生成的列。 我试图使用AutoGeneratingColumnevent(),但实际上它只能访问DataGridColumn,而不能访问DataGridViewColumn,前者没有ToolTipText属性 或者,如果我能将工具提示绑定到一个源代码上,那也太好了。目标是能够在我为基础数据表设置列的同一位置操作/设置工具提示,我通过以下方式解决了此问题: void payloadDataGrid_AutoGeneratingColumn(

我想通过编程将工具提示设置为
DataGridView
中自动生成的列。 我试图使用
AutoGeneratingColumn
event(),但实际上它只能访问
DataGridColumn
,而不能访问
DataGridViewColumn
,前者没有
ToolTipText
属性


或者,如果我能将工具提示绑定到一个源代码上,那也太好了。目标是能够在我为基础
数据表设置列的同一位置操作/设置工具提示,我通过以下方式解决了此问题:

void payloadDataGrid_AutoGeneratingColumn(object sender, DataGridAutoGeneratingColumnEventArgs e)
{
    string tooltip = null;

    switch (e.Column.Header.ToString())
    {
        case "Column 1":
            tooltip = "Tooltip 1";
            break;
        case "Column 2":
            tooltip = "Tooltip 2";
            break;
    }

    if (tooltip != null)
    {
        var style = new Style(typeof(DataGridCell));
        style.Setters.Add(new Setter(ToolTipService.ToolTipProperty, tooltip));
        e.Column.CellStyle = style;
    }
}

特定单元格的tooltiptext:

DataGridView1.Rows[3].Cells["colnameX"].ToolTipText = " hover and see me";
向特定单元格中动态添加的行添加工具提示

private void DataGridView1_RowsAdded(object sender, DataGridViewRowsAddedEventArgs e)
{
    for (int index = e.RowIndex; index <= e.RowIndex + e.RowCount - 1; index++)                           
    {
        DataGridViewRow row = DataGridView1.Rows[index];
        row.Cells["colnameX"].ToolTipText = " hover and see me";

    }
}
private void DataGridView1_RowsAdded(对象发送方,DataGridViewRowsAddedEventArgs e)
{

对于(int index=e.RowIndex;index),请围绕您的答案提供一些上下文。