Brian Ng Brian Ng - 22 days ago 5x
C# Question

C# how to get the detail gridView2 (master-Detail) FocusedColumn.FieldName? (Programmatically)

I manage to create master-detail, which shown at the attachment image.
the gridControl1 consist of 2 grid view, MainView : gridView1 (which is the master table : data table name : tableSalesOrder) and InfoDetails (Level1) : gridView2 (which is the detail table : data table name : tableDetail).

Both below code are successful for the double clicks event.

gridView1.DoubleClick += gridView1_DoubleClick;
gridView2.DoubleClick += gridView2_DoubleClick;

My issue : -

The below code is successful as my gridView1.FocusedColumn.FieldName == "ItemCode".

private void gridView1_DoubleClick(object sender, EventArgs e)
object obj;
string code;
if (gridView1.FocusedColumn.FieldName == "ItemCode")
obj = gridView1.GetFocusedRowCellValue("ItemCode");
if (obj == null) return;
code = obj.ToString();

But when i try on gridView2_DoubleClick (which for the detail grid view section), my gridView2.FocusedColumn.FieldName == "DocNo" or gridView2.GetFocusedRowCellValue("DocNo") unable to get the value at the detail grid section. It only keep show the ItemCode only, how to get the value for below 2 procedure at the detail grid view section?

gridView2.FocusedColumn.FieldName == "DocNo"

I have google the whole night still not able find any hint yet. Need the master assistance.
Thank you,

The data set and data table, I done the link by below the code

orderData.Relations.Add("InfoDetails", tableSalesOrder.Columns["ItemCode"], tableDetail.Columns["ItemCode"]);
DataRelation orderRelation = orderData.Relations["InfoDetails"];
gridControl1.DataSource = tableSalesOrder;
gridControl1.ShowOnlyPredefinedDetails = false;

the code for the check the gridView2 column name and value, i code as below

GridView gridView2 = (GridView) gridView1.GetDetailView(gridView1.FocusedRowHandle, 0);

unfortunately it got bug which i unable to solve. it work provided i don't click other master section cell. An error object message will pop up; once i click other cell at master section, and i go back to click on my previous detail cell.

enter image description here


I solved it by the below googled code with little of modification to suit by program structure.

 GridView detailView = sender as GridView;
 GridView gv = (GridView)gridView1.GetDetailView(detailView.SourceRowHandle, 0);