Version

Accessing a Specific Row in WinGrid

The way in which you access a particular row depends on the row, as well as the information you have about the row. The following procedure is an example of how to access rows in the WinGrid™ by traversing the WinGrid’s structure.

To traverse the WinGrid to access a specific row:

  1. Before you start writing any code, you should place using/imports directives in your code-behind so you don’t need to always type out a member’s fully qualified name.

In Visual Basic:

Imports Infragistics.Win.UltraWinGrid

In C#:

using Infragistics.Win.UltraWinGrid;
  1. In order to traverse the rows in the grid, you must get a reference to a row. Commonly, you will want to access the first row in the grid and work from there. You can do this with the GetRow method.

In Visual Basic:

Dim aRow As UltraGridRow
aRow = UltraGrid1.GetRow(ChildRow.First)

In C#:

UltraGridRow aRow = this.ultraGrid1.GetRow(ChildRow.First);
  1. Once you have access to the first row, you can use several methods to get references to other rows. If you want to get the next row in the same band, you would first check to see if there is a next row. To see if the row has a next sibling, you use the HasNextSibling Method.

In Visual Basic:

If aRow.HasNextSibling Then

In C#:

if(aRow.HasNextSibling())
{
  1. Once it is established there is a next sibling, you can access it by using the GetSibling method of the row.

In Visual Basic:

	Dim NextRow As UltraGridRow = aRow.GetSibling(SiblingRow.Next)
	MessageBox.Show("Has Siblings")
Else
	MessageBox.Show("Has no Siblings")
End If

In C#:

	UltraGridRow NextRow = aRow.GetSibling(SiblingRow.Next);
	MessageBox.Show("Has Siblings");
}
else
	MessageBox.Show("Has no Siblings");
  1. In a similar way, you can get a reference to a child row by using the HasChild and GetChild methods.

In Visual Basic:

If aRow.HasChild Then
	Dim ChildRow As UltraGridRow = _
	  aRow.GetChild(Infragistics.Win.UltraWinGrid.ChildRow.First)
	MessageBox.Show("Has a Child")
Else
	MessageBox.Show("Has no Child")
End If

In C#:

if(aRow.HasChild())
{
	UltraGridRow childRow = aRow.GetChild(Infragistics.Win.UltraWinGrid.ChildRow.First);
	MessageBox.Show("Has a Child");
}
else
	MessageBox.Show("Has no Child");