2016-07-01 10 views
1

DataGridのすべての行(およびすべてのセル)にツールチップを追加します。これどうやってするの?私はRowDataBoundとCellFormatingを試しましたが、私のコードでこの例を使用することはできません(同様のイベントはありません)C#.Net 4.0のDataGrid行のツールチップ

あなたはそれをどのように扱うか考えていますか?

答えて

0

例はMSDNからです。ここでは、このセルに関連付けられているツールヒントのテキストを取得または設定します。制御のイベント_CellFormattingの助けを借りて;以下のコードを考えてみましょう:

void dataGridView1_CellFormatting(object sender, DataGridViewCellFormattingEventArgs e) 
{ 
    if ((e.ColumnIndex == this.dataGridView1.Columns["column_name"].Index) && e.Value != null) 
    { 
     DataGridViewCell cell = this.dataGridView1.Rows[e.RowIndex].Cells[e.ColumnIndex]; 
     cell.ToolTipText = "This is given ToolTip"; 
    } 
} 

あなたがこの(これはあまりにも関連するリンクで説明)のようにあまりにも条件付きツールチップを試すことができます。

if (e.Value.Equals("some value")) 
{ 
    cell.ToolTipText = "ToolTip 1"; 
} 
else if (e.Value.Equals("some other value")) 
{ 
    cell.ToolTipText = "ToolTip 2"; 
} 
// Like wise