Description:
I have a master-detail grid. When I try to use the FocusedRowHandle property of the detail view, it always returns -999999. The FocusedRowHandle property of the master grid view returns the correct result. Here is my code:
C#int row = gridView2.FocusedRowHandle; // gridView2 is a detail grid view
Console.WriteLine(row); // row is always -999999
Answer:
A common mistake when performing data specific operations in master-detail mode on detail views (deleting and obtaining records, collapsing/expanding groups and master rows, etc) is using pattern views which are created at design time and used as sublevels of the GridControl. Pattern views don't contain any data and they are never displayed on screen. Pattern views only serve as templates, i.e. they provide layout settings for representing the data displayed by real detail views (clones). You can get detailed information on pattern and clone views in the XtraGrid help file.
For example, consider the following scenario:
Your master GridView has two details expanded. Both these detail views are created using the DetailGridView pattern view, right?
Then, if you call the DetailGridView .SetRowCellValue(rowHandle, fieldName, value) , it is not clear in which view you expect GridView will make changes: in the first one or in the second one? Both these views can have the same row handles and columns.
If you wish to make changes only in the focused view, in this case use methods of this view. For example, GridControl. FocusedView.SetRowCellValue(rowHandle, fieldName, value)
There are several ways to access the real grid view with which an end user interacts at runtime:
GridControl.MainView - returns the top most view in a grid
GridControl.FocusedView - returns the focused view
the sender parameter of view specific events
GridView.GetDetailView - returns a detail view for a specific master row.
After the required view is obtained, you can get the currently focused row via the view's FocusedRowHandle property or use any other property or method of the detail view.
C#using DevExpress.XtraGrid.Views.Base;
// Obtain the focused row of the currently focused view
int detailRowHandle = ((ColumnView)gridControl1.FocusedView).FocusedRowHandle;
// Obtain the focused row of a specific detail view, if expanded
// gridView1 corresponds to GridControl.MainView
int masterRowHandle = 0;
int relationIndex = 0;
if(gridView1.GetMasterRowExpandedEx(masterRowHandle, relationIndex)) {
ColumnView detailView = (ColumnView)gridView1.GetDetailView(masterRowHandle, relationIndex);
int detailRowHandle = detailView.FocusedRowHandle;
}
Visual BasicImports DevExpress.XtraGrid.Views.Base
' Obtain the focused row of the currently focused view
Dim detailRowHandle As Integer = (CType(gridControl1.FocusedView, ColumnView)).FocusedRowHandle
' Obtain the focused row of a specific detail view, if expanded
' gridView1 corresponds to GridControl.MainView
Dim masterRowHandle As Integer = 0
Dim relationIndex As Integer = 0
If gridView1.GetMasterRowExpandedEx(masterRowHandle, relationIndex) Then
Dim detailView As ColumnView = CType(gridView1.GetDetailView(masterRowHandle, relationIndex), ColumnView)
Dim detailRowHandle As Integer = detailView.FocusedRowHandle
End If
See Also:
Pattern and Clone Views
A273
A527
this post was very useful for me thanx a lot
Hi,
We are glad to hear that. Please feel free to contact us in case of any difficulties.
Thats it's Good & it's Work For me
thanks al lot…
_gridViewTD1.ExpandMasterRow(_gridViewTD1.FocusedRowHandle, 0);
int masterRowHandle = _gridViewTD1.FocusedRowHandle;
int relationIndex = 0;
if (_gridViewTD1.GetMasterRowExpandedEx(masterRowHandle, relationIndex))
{
ColumnView view1D = (ColumnView)_gridViewTD1.GetDetailView(masterRowHandle, relationIndex);
Decimal TotluasBlok1 = 0;
Decimal TotALokasiBiaya1 = 0;
view1D.Focus();
view1D.BeginDataUpdate();
int iRowD1 = 0;
int iCount1 = 0;
foreach (DataRow row1 in dvAsm3TBM.Table.Rows) //filterDv_GLokup1.Table.Rows)
{
iCount1++;
Decimal luasBlok1 = _Syb3InitPub1._mySyb3Db2.Syb3IsNullDec(row1["LUASBLOK"]);
Int16 glm3Code = _Syb3InitPub1._mySyb3Db2.Syb3IsNullInt16(row1["GLM3CODE"]);
view1D.Focus();
Decimal ALokasiBiaya1 = luasBlok1 / LuasTbm1 * totBiaya2;
view1D.AddNewRow();
iRowD1 = view1D.FocusedRowHandle;
view1D.SetRowCellValue(iRowD1, "NOURUT", iCount1);
view1D.SetRowCellValue(iRowD1, "GLM2CODE", glm2CodeRDB);
view1D.SetRowCellValue(iRowD1, "GLM3CODE", glm3Code);
view1D.SetRowCellValue(iRowD1, "FCM2CODE", row1["FCM2CODE"]);
view1D.SetRowCellValue(iRowD1, "KETDETAIL", "Alokasi Biaya Overhead " + row1["CODE"]);
view1D.SetRowCellValue(iRowD1, "LUAS", luasBlok1);
view1D.SetRowCellValue(iRowD1, "MUTDB", ALokasiBiaya1);
view1D.UpdateCurrentRow();
TotluasBlok1 = TotluasBlok1 + luasBlok1;
TotALokasiBiaya1 = TotALokasiBiaya1 + ALokasiBiaya1;
}
view1D.UpdateCurrentRow();
view1D.EndDataUpdate();
Hello,
Would you please clarify whether you need any help with the code posted above?