When you expand multiple rows of a master detail grid the property CurrentItem always returns the value of the last parent row clicked. I have attached a demo project demonstrating this.
In the picture below I am hovering over the PersonId column field. In the tooltip you can clearly see that the currentitem is reporting to me "dbo.Company". That is because "dbo.Company" was the last parent row I clicked open.
I need a way to get the parent row of the current details grid, regardless of what the current index or item is.
Your requirement to get the main grid data in ToolTipOpening event can be achieved by getting the RowIndex of ChildDataGrid using GetDetailsViewDataGridRowIndex helper method. Refer to the below code snippet,
if (e.Record != null) { //Here get the child DataGrid var detailsViewDataGrid = e.OriginalSender as DetailsViewDataGrid;
if (detailsViewDataGrid != null) { //Here get the parentDataGrid var parentDataGrid = detailsViewDataGrid.GetTopLevelParentDataGrid();
if (parentDataGrid != null) { //Here get the RowIndex of ChildDataGrid var childRowIndex = parentDataGrid.GetDetailsViewDataGridRowIndex(detailsViewDataGrid);
if (childRowIndex > -1) { //Here get the parent rowIndex by subtract 1 value from childRowIndex var parentRowIndex = childRowIndex - 1;
if (parentRowIndex > -1) { //Here get the parent record index var parentRecordIndex = parentDataGrid.TableControl.ResolveToRecordIndex(parentRowIndex);
if (parentRecordIndex > -1) { //here get the parent record var record = parentDataGrid.View?.Records[parentRecordIndex];
if (record != null) { //Here know the properties of the primary item to which the secondary grid belongs. //Here you can access that main datagrid data var datatable = record.Data as DatabaseTable; var col = e.Record as DatabaseTableColumn; //Here you can assign the secondary grid the order id as maingrid order id tt = $"{datatable.Name} {col.Name} {col.DataType}"; } } } } } } } |
Find the modified sample in the attachment.
If this post is helpful, please consider Accepting it as the solution so that
other members can locate it more quickly.
TY Vijay, that worked perfectly
If you are satisfied with our response, please mark it as an answer. Otherwise, please let us know if you have any further queries on this. We are happy to help you😊.