DataGridViewRowPostPaintEventArgs.RowIndex プロパティ
アセンブリ: System.Windows.Forms (system.windows.forms.dll 内)

現在の DataGridViewRow のインデックス。


RowIndex プロパティを使用して、現在の行にアクセスする方法を次のコード例に示します。このコードでは、選択された行と 3 番目の列の交差位置にあるセルの値を取得した後、この値を行全体に描画します。変数 e の型が DataGridViewRowPostPaintEventArgs です。次のコード例は、「方法 : Windows フォームの DataGridView コントロールの行の外観をカスタマイズする」で示されている例の一部です。
' Get the content that spans multiple columns. Dim recipe As Object = _ Me.dataGridView1.Rows.SharedRow(e.RowIndex).Cells(2).Value If Not (recipe Is Nothing) Then Dim text As String = recipe.ToString() ' Calculate the bounds for the content that spans multiple ' columns, adjusting for the horizontal scrolling position ' and the current row height, and displaying only whole ' lines of text. Dim textArea As Rectangle = rowBounds textArea.X -= Me.dataGridView1.HorizontalScrollingOffset textArea.Width += Me.dataGridView1.HorizontalScrollingOffset textArea.Y += rowBounds.Height - e.InheritedRowStyle.Padding.Bottom textArea.Height -= rowBounds.Height - e.InheritedRowStyle.Padding.Bottom textArea.Height = (textArea.Height \ e.InheritedRowStyle.Font.Height) * _ e.InheritedRowStyle.Font.Height ' Calculate the portion of the text area that needs painting. Dim clip As RectangleF = textArea clip.Width -= Me.dataGridView1.RowHeadersWidth + 1 - clip.X clip.X = Me.dataGridView1.RowHeadersWidth + 1 Dim oldClip As RectangleF = e.Graphics.ClipBounds e.Graphics.SetClip(clip) ' Draw the content that spans multiple columns. e.Graphics.DrawString(text, e.InheritedRowStyle.Font, forebrush, _ textArea) e.Graphics.SetClip(oldClip) End If
// Get the content that spans multiple columns. object recipe = this.dataGridView1.Rows.SharedRow(e.RowIndex).Cells[2].Value; if (recipe != null) { String text = recipe.ToString(); // Calculate the bounds for the content that spans multiple // columns, adjusting for the horizontal scrolling position // and the current row height, and displaying only whole // lines of text. Rectangle textArea = rowBounds; textArea.X -= this.dataGridView1.HorizontalScrollingOffset; textArea.Width += this.dataGridView1.HorizontalScrollingOffset; textArea.Y += rowBounds.Height - e.InheritedRowStyle.Padding.Bottom; textArea.Height -= rowBounds.Height - e.InheritedRowStyle.Padding.Bottom; textArea.Height = (textArea.Height / e.InheritedRowStyle.Font.Height) * e.InheritedRowStyle.Font.Height; // Calculate the portion of the text area that needs painting. RectangleF clip = textArea; clip.Width -= this.dataGridView1.RowHeadersWidth + 1 - clip.X; clip.X = this.dataGridView1.RowHeadersWidth + 1; RectangleF oldClip = e.Graphics.ClipBounds; e.Graphics.SetClip(clip); // Draw the content that spans multiple columns. e.Graphics.DrawString( text, e.InheritedRowStyle.Font, forebrush, textArea); e.Graphics.SetClip(oldClip); }

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


- DataGridViewRowPostPaintEventArgs.RowIndex プロパティのページへのリンク