【问题标题】:Setting ToolTip for DataGridView automatically created columns为 DataGridView 设置 ToolTip 自动创建的列
【发布时间】:2013-09-09 13:47:51
【问题描述】:
【问题讨论】:
标签:
c#
wpf
datagridview
tooltip
autogeneratecolumn
【解决方案1】:
我设法以这种方式解决了它:
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;
}
}
【解决方案2】:
特定单元格的工具提示文本:
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";
}
}