If page-mode navigation is enabled, use the MakeRowVisible method to switch to the page which displays the specified data row (if required). If the row is not found, the MakeRowVisible method does nothing and returns false.
Note
The MakeRowVisible method is not in effect if the endless paging mode is enabled.
This example demonstrates how you can respond to insertion of a new master row into the grid to allow an end-user to enter the corresponding details immediately.In this sample, the ASPxGridView is used in master-detail mode. Grid detail rows are represented by an ASPxPageControl, which is placed within the grid's DetailRow template.
The ASPxPageControl has two tab pages, which contain different UserControls.
The first tab page has an ASPxMemo editor displaying master row description info. The second tab page's content is represented by another ASPxGridView control that maintains master row details.
By default, the first tab page is active.After an end-user inserts a new master row into the master grid, it is required to focus this row, open its detail row, make the ASPxPageControl's second tab page active and switch the detail grid to the insert mode.This behavior is implemented by handling the master ASPxGridView's RowInserting event and the ASPxPageControl's DataBound event.
ImportsMicrosoft.VisualBasicImportsSystemImportsDevExpress.WebPartialPublicClass WebUserControl2
Inherits System.Web.UI.UserControl
ProtectedSub Page_Load(ByVal sender AsObject, ByVal e As EventArgs)
EndSubProtectedSub gvDetail_BeforePerformDataSelect(ByVal sender AsObject, ByVal e As EventArgs)
Session("MasterID") = (TryCast(sender, ASPxGridView)).GetMasterRowKeyValue()
EndSubProtectedSub gvDetail_InitNewRow(ByVal sender AsObject, ByVal e As DevExpress.Web.Data.ASPxDataInitNewRowEventArgs)
Session("MasterID") = (TryCast(sender, ASPxGridView)).GetMasterRowKeyValue()
e.NewValues("MasterID") = Session("MasterID").ToString()
EndSubProtectedSub GridView_RowInserting(ByVal sender AsObject, ByVal e As DevExpress.Web.Data.ASPxDataInsertingEventArgs)
Dim gridView As ASPxGridView = CType(sender, ASPxGridView)
Dim gridDataSource AsNew GridDataSource()
gridDataSource.InsertRow(e.NewValues, gridView.SettingsDetail.IsDetailGrid)
gridView.CancelEdit()
e.Cancel = TrueEndSubProtectedSub gvDetail_CellEditorInitialize(ByVal sender AsObject, ByVal e As ASPxGridViewEditorEventArgs)
Dim gridView As ASPxGridView = CType(sender, ASPxGridView)
If e.Column.FieldName = "MasterID"ThenDim textBoxMasterID As ASPxTextBox = CType(e.Editor, ASPxTextBox)
If textBoxMasterID.Value IsNothingThen
textBoxMasterID.Value = gridView.GetMasterRowKeyValue()
EndIfEndIfEndSubEndClass
ImportsMicrosoft.VisualBasicImportsSystemImportsDevExpress.WebPartialPublicClass _Default
Inherits System.Web.UI.Page
ProtectedSub Page_Load(ByVal sender AsObject, ByVal e As EventArgs)
EndSubProtectedSub GridView_RowInserting(ByVal sender AsObject, ByVal e As DevExpress.Web.Data.ASPxDataInsertingEventArgs)
Dim gridView As ASPxGridView = CType(sender, ASPxGridView)
Dim gridDataSource AsNew GridDataSource()
gridDataSource.InsertRow(e.NewValues, gridView.SettingsDetail.IsDetailGrid)
gridView.CancelEdit()
e.Cancel = True'Navigate to the newly inserted row within the grid and open its detailsDim newRowIndex AsInteger = gridView.FindVisibleIndexByKeyValue(e.NewValues("ID"))
gridView.PageIndex = newRowIndex / gridView.SettingsPager.PageSize
gridView.DetailRows.ExpandRow(newRowIndex)
activeTabIndex = 1EndSubPrivate activeTabIndex As Nullable(OfInteger)
ProtectedSub ASPxPageControl1_DataBound(ByVal sender AsObject, ByVal e As EventArgs)
If activeTabIndex.HasValue Then'Change the ASPxPageControl's active tab page, and switch the detail grid to insert modeDim pageControl As ASPxPageControl = TryCast(sender, ASPxPageControl)
pageControl.ActiveTabIndex = activeTabIndex.Value
Dim detailGrid As ASPxGridView = TryCast(pageControl.FindControl("WebUserControl2").FindControl("gvDetail"), ASPxGridView)
detailGrid.AddNewRow()
EndIfEndSubEndClass
ImportsMicrosoft.VisualBasicImportsSystemImportsSystem.DataImportsSystem.WebImportsSystem.Web.SessionStateImportsSystem.ComponentModelImportsSystem.CollectionsImportsSystem.Collections.SpecializedPublicClass GridDataSource
PrivateReadOnlyProperty Session() As HttpSessionState
GetReturn HttpContext.Current.Session
EndGetEndPropertyPublicFunction GetMasterRows() As DataTable
ReturnTryCast(GetDataSource().Tables("MasterTable"), DataTable)
EndFunctionPublicFunction GetDetailRows(ByVal masterId AsInteger) As DataView
Dim detailTable As DataTable = GetDataSource().Tables("DetailTable")
Dim dataView AsNew DataView(detailTable)
dataView.RowFilter = "MasterID = " & Session("MasterID").ToString()
Return dataView
EndFunctionPublicSub InsertRow(ByVal newValues As OrderedDictionary, ByVal isDetail AsBoolean)
Dim dataTable As DataTable = GetDataTable(isDetail)
Dim row As DataRow = dataTable.NewRow()
newValues("ID") = dataTable.Rows.Count
Dim enumerator As IDictionaryEnumerator = newValues.GetEnumerator()
enumerator.Reset()
DoWhile enumerator.MoveNext()
If enumerator.Key.ToString() <> "Count"Then
row(enumerator.Key.ToString()) = enumerator.Value
EndIfLoopIf (Not isDetail) Then
row("Description") = "Auto generated description for Master Row " & newValues("ID").ToString()
EndIf
dataTable.Rows.Add(row)
EndSubPublicFunction GetRowCount(ByVal isDetail AsBoolean) AsIntegerReturn GetDataTable(isDetail).Rows.Count
EndFunctionPrivateFunction GetDataTable(ByVal isDetail AsBoolean) As DataTable
If isDetail ThenReturn GetDataSource().Tables("DetailTable")
ElseReturn GetDataSource().Tables("MasterTable")
EndIfEndFunctionPrivateFunction GetDataSource() As DataSet
If Session("GridDataSource") IsNothingThen
CreateGridDataSource()
EndIfReturnTryCast(Session("GridDataSource"), DataSet)
EndFunctionPrivateSub CreateGridDataSource()
'Create a master table's structureDim masterTable AsNew DataTable("MasterTable")
masterTable.Columns.Add("ID", GetType(Integer))
masterTable.Columns.Add("Data", GetType(String))
masterTable.Columns.Add("Description", GetType(String))
masterTable.PrimaryKey = New DataColumn() { masterTable.Columns("ID") }
'Create a detail table's structureDim detailTable AsNew DataTable("DetailTable")
detailTable.Columns.Add("ID", GetType(Integer))
detailTable.Columns.Add("MasterID", GetType(Integer))
detailTable.Columns.Add("DetailData", GetType(String))
detailTable.PrimaryKey = New DataColumn() { detailTable.Columns("ID") }
'Populate data tablesDim index AsInteger = 0For i AsInteger = 0To14
masterTable.Rows.Add(NewObject() { i, "Master Row " & i.ToString(), "Description for Master Row " & i.ToString() })
For j AsInteger = 0To4
detailTable.Rows.Add(NewObject() { index, i, "Detail Row " & j.ToString() })
index += 1Next j
Next i
'Add tables to a data source, and store it within a Session Dim ds AsNew DataSet()
ds.Tables.AddRange(New DataTable() { masterTable, detailTable })
Session("GridDataSource") = ds
EndSubEndClass