0

I haven't found any satisfactory answer or solution to my problem. I have a master - detail grid (2 levels only), single selection only. Some relevant code:

<dxg:GridControl AutoGenerateColumns="None" Name="gridControlMaster" AutoExpandAllGroups="True">
    <dxg:GridControl.View>
        <dxg:TableView ShowGroupPanel="False" />
    </dxg:GridControl.View>
    <dxg:GridControl.Columns>
        <dxg:GridColumn FieldName="Entry.Date" Header="Entry date" Visible="True" AllowEditing="False" />
    </dxg:GridControl.Columns>
    <dxg:GridControl.DetailDescriptor>
        <dxg:DataControlDetailDescriptor ItemsSourcePath="EntrySubList" ShowHeader="False">
            <dxg:DataControlDetailDescriptor.DataControl>
                <dxg:GridControl AutoGenerateColumns="None" AutoExpandAllGroups="True">
                    <dxg:GridControl.View>
                            <dxg:TableView AutoWidth="True" ShowGroupPanel="False" ShowColumnHeaders="False" />
                        </dxg:GridControl.View>
                    <dxg:GridControl.Columns>
                        <dxg:GridColumn FieldName="Label" Header="Label" Visible="True" AllowEditing="False" />
                        <dxg:GridColumn FieldName="Value" Header="Value" Visible="True" AllowEditing="False" />
                    </dxg:GridControl.Columns>
                </dxg:GridControl>
            </dxg:DataControlDetailDescriptor.DataControl>
        </dxg:DataControlDetailDescriptor>
    </dxg:GridControl.DetailDescriptor>
</dxg:GridControl>

At some point (say some button click outside the GridControl) I need the currently selected item of the master grid, regardless of the selected sub-item in the detail grid! Currently, if I click some row in the master grid and then some row in the detail grid (having some other parent than previously selected row in master grid), the CurrentItem or SelectedItem is not the desired one (it is the last selected item of the master grid, when it should be at least the parent of currently highlited detail item). This can be misleading for user.

The ideal solution would be having some kind of "selection unit", in my case being the whole master item, together with all of the children items (in detail grid). So, on whichever item in grid user clicks, master or detail, the master item and all of its children are selected (highlited). CurrentItem of the master grid is the currently selected parent item.

Another possible solution would be to only allow selecting the master grid items - and to prevent selection in detail grid (only setting SelectionMode = none on detail GridControl doesn't do that!). Another good feature in this case would be that clicking on child item (trying to select it) selects its parent in master grid.

If any further information is needed, I will provide it.

Thank you for the answer.

Federico Berasategui
  • 43,562
  • 11
  • 100
  • 154
dabor
  • 127
  • 1
  • 3
  • 13

2 Answers2

1

As far as i can see, the problem you described had already discussed in DevExpress Support Center in the context of Master-detail grid SelectedItem behaves unexpectedly when clicking detail rows thread. The solution provided in this thread - creating an additional property associated with a master View's selected item and updating of this property within the FocusedViewChanged event handler. Please, take a look at the sample project attached to the discussion mentioned above. I believe it should push you into the right direction.

DmitryG
  • 17,677
  • 1
  • 30
  • 53
0

thank you for your pointer, it really helped me. I've already tried with FocusedView property before, but apparently not the right way (perhaps on the wrong grid level). Your answer and link helped me to solve my problem.

I did something like this:

<dxg:GridControl AutoGenerateColumns="None" Margin="0,36,1,0" Name="gridControlMaster" AutoExpandAllGroups="True">
                                            <dxg:GridControl.View>
                                                <dxg:TableView ShowGroupPanel="False" FocusedViewChanged="gridControlMaster_TableView_FocusedViewChanged" />

void gridControlMaster_TableView_FocusedViewChanged(object sender, FocusedViewChangedEventArgs e)
{
            int rowHandle = ((GridControl)e.NewView.DataControl).GetMasterRowHandle();
            if (GridControl.InvalidRowHandle == rowHandle) return;                            

            gridControlMaster.SelectedItem = gridControlMaster.GetRow(rowHandle);
}

Some test TextBox bound to SelectedItem property of the master GridControl shows the right master record being selected when selecting subitems in Detail GridControl. This is good enough for me for now.

dabor
  • 127
  • 1
  • 3
  • 13