Main Menu
Knowledge Base
Product Registration
Log an Incident
Request a Feature
Search Incidents/Bug Reports


Search KB

Please note: In an effort to better serve you, we are in the process of restructuring DevCenter. In the process, we have moved many items that you may be used to finding in DevCenter over to the Main Site. If you are having trouble locating something, please try looking at the following places:

Knowledge Base Article: KB01701

HOWTO:UltraWinGrid Row selection and the Active Row


The information in this article applies to:
UltraWinGrid (v1.0.5005)
  Article Created: 
7/12/2002

Last Updated:
7/12/2002

Article Type
How To
  
Page Options
Average Rating:
2 out of 10

Rate this page
Print this page
E-mail this page
Add to Favorites

Summary

The UltraWinGrid generally has an Active Row, which is a reference to a single row in any of the bands. Visually the Active Row is identified by a triangle pointing to the right. The developer has direct access to the Active Row with the .ActiveRow property of an instance of the UltraWinGrid.

Additional Information

Questions
How to tell if there is an ActiveRow?
How to change the ActiveRow through code?
What events fire when the ActiveRow changes?

Solutions
ActiveRow will be equal Nothing if there is no active row.
The developer can set ActiveRow to an instance of an UltraWinGrid Row object.
When ActiveRow changes the following events fire:
BeforeRowDeactivate
BeforeRowActivate
AfterRowActivate

Step-By-Step Example

This project illustrates when Row Selection is performed and how to interact with the ActiveRow property of the grid.

This project consists of the following classes:
clsCustomerData - provides a method for creating the Customers DataTable. This Class is not reviewed.
clsCustOrderData - provides a method for creating the Customer Orders DataSet. This Class is not reviewed.
clsOrderData - provides a method for creating the Orders DataTable. This Class is not reviewed.
Form1 - contains the code relevant to this project and consists of the following relevant code Regions:
Form Events

FormLoad - contains the code used to initialize the event viewer TextBox, create the Customer Orders DataSet and bind it to the UltraWinGrid:

' initialize event viewer TextBox
TextBox1.Text = "Initial Launch Events:" + vbCrLf

' create Customer Orders DataSet and Bind To Grid
Dim CustOrderDataSet As New clsCustOrderDataSet()
UltraGrid1.DataSource = CustOrderDataSet.MakeCustOrderDataSet

UltraWinGrid Events

InitializeLayout - contains the code used to initialize the grid layout:

' set grid layout properties
e.Layout.AutoFitColumns = True

AfterRowActivate - event adds an entry to the Event Viewer:

' add event to Event Viewer
TextBox1.Text += "--AfterRowActivate" + vbCrLf

BeforeRowDeActivate - event adds an entry to the Event Viewer:

' add event to Event Viewer
TextBox1.Text += "--BeforeRowDeactivate" + vbCrLf

BeforeRowActivate - event adds an entry to the Event Viewer:

' add event to Event Viewer
TextBox1.Text += "--BeforeRowActivate" + vbCrLf

MouseDown - event adds an entry to the Event Viewer:

' add event to Event Viewer
TextBox1.Text = "MouseDown:" + vbCrLf

KeyDown - event adds an entry to the Event Viewer if the key pressed is not the Alt key. The Alt key is swallowed by this event so the state of the display does not change when pressing 'Alt-PrintScreen' to capture a screen shot:

' add event to Event Viewer
If e.Modifiers = Keys.Alt Then

e.Handled = True

Else

TextBox1.Text = "KeyDown:" + vbCrLf

End If

MouseUp - event adds an entry to the Event Viewer, then attempts to retrieve and display the value of the cell on which the event occurred:

' add event to Event Viewer
TextBox1.Text += "--MouseUp" + vbCrLf

' declare objects to get value from cell and display
Dim mouseupUIElement As Infragistics.Win.UIElement
Dim mouseupCell As Infragistics.Win.UltraWinGrid.UltraGridCell
Dim mouseupValue As Object
Dim mouseupValueType As System.Type
Dim strValue As String

' retrieve the UIElement from the location of the MouseUp
mouseupUIElement _

= UltraGrid1.DisplayLayout.UIElement.ElementFromPoint(New Point(e.X, e.Y))


' retrieve the Cell from the UIElement
mouseupCell _

= mouseupUIElement.GetContext _
(GetType(Infragistics.Win.UltraWinGrid.UltraGridCell))


' if there is a Cell associated with the UIElement, retrieve the
' cell value type. Then based on the cell value type retrieve
' the value and convert it to a string and add to Event Viewer.
If Not mouseupCell Is Nothing Then


mouseupValueType = mouseupCell.Value.GetType

If mouseupValueType.Equals(GetType(Int32)) Then ' Int32

Dim aInt32 As Int32 = mouseupCell.Value
strValue = aInt32.ToString


ElseIf mouseupValueType.Equals(GetType(String)) Then ' String

Dim aString As String = mouseupCell.Value
strValue = aString.ToString


ElseIf mouseupValueType.Equals(GetType(Date)) Then ' Date

Dim aDate As Date = mouseupCell.Value
strValue = aDate.ToString

End If

TextBox1.Text += "--MouseUp on Cell Value=" + strValue


End If

Button Events

The Button Events demonstrate two different ways to pass rows in the UltraWinGrid in search of one specific row
Set Active Row to CustomerID=2 - passes the rows of Band 0 looking for a row with the “CustomerID” column value = 2. If the project does not use Group By, then the UltraGrid.Rows collection can be used to pass all of the rows in Band 0:

Dim gridRow As Infragistics.Win.UltraWinGrid.UltraGridRow
Dim intRow As Integer

' add event to Event Viewer
TextBox1.Text = "Set Active Row to CustomerID=2:" + vbCrLf

' pass rows of UltraWinGrid Bands(0) until CustomerID = 2
' the UltraGrid.Rows collection contains all of the band 0 rows
' or the top level of Group By Rows if Group By is being used.
For intRow = 0 To UltraGrid1.Rows.Count - 1

gridRow = UltraGrid1.Rows(intRow)
If gridRow.Band.Index = 0 Then

If gridRow.Cells("CustomerID").Value = 2 Then

UltraGrid1.ActiveRow = gridRow
gridRow.Expanded = True
Exit Sub

End If

End If

Next intRow

Set Active Row to CustomerID=2, OrderID=4 - passes all of the rows in all of the bands looking for a band 1 record with a CustomerID = 2 and an OrderID = 4. This code is interesting in that it passes all of the bands and rows of the hierarchical grid:

Dim gridRow As Infragistics.Win.UltraWinGrid.UltraGridRow

' add event to Event Viewer
TextBox1.Text = "Set Active Row to CustomerID=2, OrderID=4:" + vbCrLf

' setup to loop through all rows of all bands
gridRow = UltraGrid1.GetRow(Infragistics.Win.UltraWinGrid.ChildRow.First)
Do Until gridRow Is Nothing


' process selected row if found
If gridRow.Band.Index = 1 Then

If gridRow.Cells("CustomerID").Value = 2 Then

If gridRow.Cells("OrderID").Value = 4 Then

UltraGrid1.ActiveRow = gridRow
UltraGrid1.ActiveRow.ParentRow.Expanded = True
Exit Sub

End If

End If

End If

' look for child
If gridRow.HasChild = True Then

gridRow _
= gridRow.GetChild(Infragistics.Win.UltraWinGrid.ChildRow.First)

' look for sibling

ElseIf gridRow.HasNextSibling = True Then

gridRow _
= gridRow.GetSibling(Infragistics.Win.UltraWinGrid.SiblingRow.Next)

' look for parent with siblings

ElseIf gridRow.Band.Index > 0 Then

Do Until gridRow.HasNextSibling = True

If gridRow.Band.Index > 0 Then

gridRow = gridRow.ParentRow

Else

gridRow = Nothing
Exit Do

End If

Loop

' we get here get the next sibling row
If Not gridRow Is Nothing Then

gridRow _
= gridRow.GetSibling(Infragistics.Win.UltraWinGrid.SiblingRow.Next)

End If

' last row of band zero

Else

gridRow = Nothing

End If

Loop

Review
This is a very interesting project in that it reviews many different ways to interact with the .ActiveRow of the grid. There are three extremely relevant code sections:

The MouseUp event code used to determine if a cell was under the MouseUp and displaying the value of cells with various DataTypes.
The Set Active Row to CustomerID=2 event code used to pass all of the rows in band 0.
The Set Active Row to CustomerID=2, OrderID=4 event code used to pass all of the rows in an hierarchical grid.

Samples

ultrawingrid_tutorial_row_selection_and_active_row.zip
 UltraWinGrid Row Selection And Active Row



How would you rate the quality of this content?
Poor -----------------------------------------> Outstanding

Tell us why you rated the content this way. (optional)