We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. Image for the cookie policy date

Select a line in the detail section of a Master-Detail datagrid

Ho, 

Is there a way to select an item dynamically (with line code) in the detail part of a master-detail datagrid ?

I try to set the CurrentItem / SelectedItem with the Behaviour workaround but it does not work to set only to get.

Regards.

9 Replies

SP Sowndaiyan Paulpandi Syncfusion Team October 26, 2015 09:17 AM UTC

Hi MARQUANT,

Thanks for using Syncfusion Products.

You can set the value to CurrentItem as well as SelectedItem in SfDataGrid like the below code example.

Code Example[C#]:



void FirstDetailsViewDataGridSelectionChanged(object sender, GridSelectionChangedEventArgs e)
        {
            var OrderDetailCollection = this.AssociatedObject.DataContext as ViewModel;
 
            var CurrentItemDetails = OrderDetailCollection.OrdersDetails[2].OrderDetails[0] as OrderDetails;
            var SelectedItemDetails = OrderDetailCollection.OrdersDetails[3].OrderDetails[0] as OrderDetails;
 
            //Set the Specific OrderDetails to the CurrentItem/SelectedItem
            (e.OriginalSender as SfDataGrid).CurrentItem = CurrentItemDetails;
            (e.OriginalSender as SfDataGrid).SelectedItem = SelectedItemDetails;
 
            this.DetailsViewSelectedItem = (e.OriginalSender as SfDataGrid).SelectedItem;
          
            this.DetailsViewSelectedItems = (e.OriginalSender as SfDataGrid).SelectedItems;
          
            this.DetailsViewCurrentItem = (e.OriginalSender as SfDataGrid).CurrentItem;
       }



We have prepared a sample for setting the values to the CurrentItem and SelectedItem of SfDataGrid using the “Behavior” concept. In this sample, we have set the particular record to SfDataGrid.CurrentItem  and SfDataGrid.SelectedItem in the SelectionChanged Event and you can download that sample from the below location,


Sample Link: http://www.syncfusion.com/downloads/support/forum/120886/ze/MasterDetailsView-2006844171



Regards,
Sowndaiyan




MC MARQUANT Cédric October 27, 2015 06:24 AM UTC

Hi,

thanks for your proposal but unfortunatley it does not perform what I want.

I would have to set the currentitem / selecteditem only when I launch an Add action on the collection in the view model to set the current row on the added item.

If I add your code, the selected item is always set to the same row.

Is there a way to do that ?

Thanks again for your help.

Regards


SP Sowndaiyan Paulpandi Syncfusion Team October 29, 2015 03:49 AM UTC

 

Hi MARQUANT,

We have analyzed your query. We regret to inform you that it is not possible to set the CurrentItem / SelectedItem when performing the Add action in view model. Because it is not possible to get the exact DetailViewDataGrid in Add action. So we recommend you to use the “Behaviour” concept.

Please let us know if you require further assistance on this.


Regards,
Sowndaiyan



MC MARQUANT Cédric October 31, 2015 06:57 PM UTC

Is there a way to set always the first line after I add a new record in the details part of the Datagrid ?


SP Sowndaiyan Paulpandi Syncfusion Team November 3, 2015 03:58 AM UTC

Hi MARQUANT,

We have analyzed your query and we have prepared the sample based upon your requirement “Set the CurrentItem / SelectedItem in add action of the DetailsViewDataGrid” . You can download the sample from the following location.


Sample Location:
http://www.syncfusion.com/downloads/support/forum/120886/ze/DetailsViewDemo202407730

In this sample we have add the record into the DetailsView on a ButtonClick action using ICommand. Within this action we have set the CurrentItem / SelectedItem to the Corresponding DetailsViewDataGrid.

Please let us know if you have any other concern.

Regards,
Sowndaiyan




MC MARQUANT Cédric November 3, 2015 06:56 PM UTC

It's a good way to achieve my requirement but there is again a little problem.

With your sample the RecordIndex is set to 0 and so the first Child Datagrid is always updated even if I added a record in the second one.

Is there a way to find the RecordIndex currently selected to update the good child datagrid ?

Regards,


FP Farjana Parveen Ayubb Syncfusion Team November 4, 2015 11:50 AM UTC

Hi Marquant,
We have analyzed your query and we have passed the recordIndex as zero for your reference to select the first record while adding in the first DetailsViewDataGrid. You have to pass the corresponding parent recordIndex of particular DetailsViewDataGrid to GetDetailsViewGrid method. Please refer the below sample for your reference.
Sample Link: DetailsViewDemo

In the above sample, we got the recordIndex by resolving the rowIndex using SfDataGrid.ResolveToRecordIndex method. If the issue still persists, could you please modify the above sample to replicate the issue that would be more helpful for us to provide you the better solution.

Regards,
Farjana Parveen A


MC MARQUANT Cédric November 4, 2015 04:29 PM UTC

Thanks it works perfectly


SP Sowndaiyan Paulpandi Syncfusion Team November 5, 2015 09:50 AM UTC

Hi Marquant,

Thanks for the update.


Please let us know if you need further assistance.
Regards,
Sowndaiyan

Loader.
Live Chat Icon For mobile
Up arrow icon