DataGridView.CellToolTipTextNeeded イベント
アセンブリ: System.Windows.Forms (system.windows.forms.dll 内)

Dim instance As DataGridView Dim handler As DataGridViewCellToolTipTextNeededEventHandler AddHandler instance.CellToolTipTextNeeded, handler
public: event DataGridViewCellToolTipTextNeededEventHandler^ CellToolTipTextNeeded { void add (DataGridViewCellToolTipTextNeededEventHandler^ value); void remove (DataGridViewCellToolTipTextNeededEventHandler^ value); }

CellToolTipTextNeeded イベントは、DataGridView コントロールの DataSource プロパティが設定されているか、VirtualMode プロパティが true の場合にだけ発生します。
CellToolTipTextNeeded イベントを処理すると、マウス ポインタがセルの上にあり、コントロールの ShowCellToolTips プロパティ値が true のときは、ハンドラで指定したツールヒント テキストが表示されます。CellToolTipTextNeeded イベントは、セルの現在の状態または値によって決定されたツールヒントを表示する場合に便利です。
CellToolTipTextNeeded イベントは、プログラムによって、またはマウス ポインタがセルに入ったときに、DataGridViewCell.ToolTipText プロパティの値が取得されたときにも発生します。
DataGridViewCellEventArgs.ColumnIndex プロパティと RowIndex プロパティを使用すると、セルの状態または値を確認し、この情報を使用して DataGridViewCellToolTipTextNeededEventArgs.ToolTipText プロパティを変更または修正できます。このプロパティは、セルの ToolTipText プロパティの値によって初期化され、イベントの値によってオーバーライドされます。
大量のデータを処理するときは、CellToolTipTextNeeded イベントを処理してください。この結果、複数のセルに対してセルの ToolTipText 値を設定することによるパフォーマンスの低下を防止できます。詳細については、「Windows フォーム DataGridView コントロールを拡張するための推奨される手順」を参照してください。

CellToolTipTextNeeded イベント ハンドラを使用して、データ バインド DataGridView コントロールの非表示列から情報を表示するコード例を次に示します。
Public Sub dataGridView1_CellToolTipTextNeeded(ByVal sender As Object, _ ByVal e As DataGridViewCellToolTipTextNeededEventArgs) _ Handles dataGridView1.CellToolTipTextNeeded Dim newLine As String = Environment.NewLine If e.RowIndex > -1 Then Dim dataGridViewRow1 As DataGridViewRow = _ dataGridView1.Rows(e.RowIndex) ' Add the employee's ID to the ToolTipText. e.ToolTipText = String.Format("EmployeeID {0}: {1}", _ dataGridViewRow1.Cells("EmployeeID").Value.ToString(), _ newLine) ' Add the employee's name to the ToolTipText. e.ToolTipText += String.Format("{0} {1} {2} {3}", _ dataGridViewRow1.Cells("TitleOfCourtesy").Value.ToString(), _ dataGridViewRow1.Cells("FirstName").Value.ToString(), _ dataGridViewRow1.Cells("LastName").Value.ToString(), _ newLine) ' Add the employee's title to the ToolTipText. e.ToolTipText += String.Format("{0}{1}{2}", _ dataGridViewRow1.Cells("Title").Value.ToString(), _ newLine, newLine) ' Add the employee's contact information to the ToolTipText. e.ToolTipText += String.Format("{0}{1}{2}, ", _ dataGridViewRow1.Cells("Address").Value.ToString(), newLine, _ dataGridViewRow1.Cells("City").Value.ToString()) If Not String.IsNullOrEmpty( _ dataGridViewRow1.Cells("Region").Value.ToString()) e.ToolTipText += String.Format("{0}, ", _ dataGridViewRow1.Cells("Region").Value.ToString()) End If e.ToolTipText += String.Format("{0}, {1}{2}{3} EXT:{4}{5}{6}", _ dataGridViewRow1.Cells("Country").Value.ToString(), _ dataGridViewRow1.Cells("PostalCode").Value.ToString(), _ newLine, _ dataGridViewRow1.Cells("HomePhone").Value.ToString(), _ dataGridViewRow1.Cells("Extension").Value.ToString(), _ newLine, newLine) ' Add employee information to the ToolTipText. Dim HireDate As DateTime = _ CType(dataGridViewRow1.Cells("HireDate").Value, DateTime) e.ToolTipText += _ String.Format("Employee since: {0}/{1}/{2}{3}Manager: {4}", _ HireDate.Month.ToString(), HireDate.Day.ToString(), _ HireDate.Year.ToString(), newLine, _ dataGridViewRow1.Cells("Manager").Value.ToString()) End If End Sub
void dataGridView1_CellToolTipTextNeeded(object sender, DataGridViewCellToolTipTextNeededEventArgs e) { string newLine = Environment.NewLine; if (e.RowIndex > -1) { DataGridViewRow dataGridViewRow1 = dataGridView1.Rows[e.RowIndex]; // Add the employee's ID to the ToolTipText. e.ToolTipText = String.Format("EmployeeID {0}:{1}", dataGridViewRow1.Cells["EmployeeID"].Value, newLine); // Add the employee's name to the ToolTipText. e.ToolTipText += String.Format("{0} {1} {2}{3}", dataGridViewRow1.Cells["TitleOfCourtesy"].Value.ToString() , dataGridViewRow1.Cells["FirstName"].Value.ToString(), dataGridViewRow1.Cells["LastName"].Value.ToString(), newLine); // Add the employee's title to the ToolTipText. e.ToolTipText += String.Format("{0}{1}{2}", dataGridViewRow1.Cells["Title"].Value.ToString(), newLine, newLine); // Add the employee's contact information to the ToolTipText. e.ToolTipText += String.Format("{0}{1}{2}, ", dataGridViewRow1.Cells["Address"].Value.ToString(), newLine , dataGridViewRow1.Cells["City"].Value.ToString()); if (!String.IsNullOrEmpty( dataGridViewRow1.Cells["Region"].Value.ToString())) { e.ToolTipText += String.Format("{0}, ", dataGridViewRow1.Cells["Region"].Value.ToString()); } e.ToolTipText += String.Format("{0}, {1}{2}{3} EXT:{4}{5}{6}", dataGridViewRow1.Cells["Country"].Value.ToString(), dataGridViewRow1.Cells["PostalCode"].Value.ToString(), newLine, dataGridViewRow1.Cells["HomePhone"].Value.ToString() , dataGridViewRow1.Cells["Extension"].Value.ToString(), newLine, newLine); // Add employee information to the ToolTipText. DateTime HireDate = (DateTime)dataGridViewRow1.Cells["HireDate"].Value; e.ToolTipText += String.Format("Employee since: {0}/{1}/{2}{3}Manager: {4}" , HireDate.Month.ToString(), HireDate.Day.ToString(), HireDate.Year.ToString(), newLine, dataGridViewRow1.Cells["Manager"].Value.ToString()); } }

Windows 98, Windows 2000 SP4, Windows Millennium Edition, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition
開発プラットフォームの中には、.NET Framework によってサポートされていないバージョンがあります。サポートされているバージョンについては、「システム要件」を参照してください。


DataGridView クラス
DataGridView メンバ
System.Windows.Forms 名前空間
DataGridView.DataSource プロパティ
DataGridView.VirtualMode プロパティ
DataGridView.ShowCellToolTips プロパティ
DataGridViewCellToolTipTextNeededEventHandler
DataGridViewCellToolTipTextNeededEventArgs
DataGridViewCellToolTipTextNeededEventArgs.ToolTipText
DataGridViewCell.ToolTipText
OnCellToolTipTextNeeded
その他の技術情報
DataGridView コントロール (Windows フォーム)
- DataGridView.CellToolTipTextNeeded イベントのページへのリンク