We need a custom button on a Subgrid for an entity that is enabled only when exactly one record is selected.
The button should be disabled when no records are selected or when more than one record is selected, and should only become active when a single record is selected.
First Go to the solutions in your Dynamcis 365 and then create your ribbon solution

Next , Go to the RibbonWorkBench and open your ribbon solution
Add your button to the Grid

In your Command add new Enable Rule with SelectionCountRule and Add your minimum and maximum number of records , in our scenario we will assign Max=1 and Min = 1 then publish

Output

