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
close icon

GridDataControl -- Automatically show details view for selected row, and hide expander cell

Hi,

so I have something like this:

        <syncfusion:GridDataControl Name="dataGrid"
                                    SelectedItem="{uxf:TwoWayBinding SelectedItem}"          
                                    ItemsSource="{uxf:TwoWayBinding Deliveries}">
            <syncfusion:GridDataControl.DetailsViewTemplate>
                <DataTemplate>
                    <StackPanel x:Name="details">
                        <local:DeliveryDetail />
                    </StackPanel>
                </DataTemplate>
            </syncfusion:GridDataControl.DetailsViewTemplate>
        </syncfusion:GridDataControl>

Which gives me the basics of what I need, but what I would like to do is always show the details for the currently selected row, and remove the ability to manually expand/hide the details.
 
What would be the easiest way to go about this?


3 Replies

TV Thangapriya V Syncfusion Team June 24, 2013 03:51 AM UTC

Hi Soren,

Sorry for the delay caused.

We have analysed your requirements. You can achieve your requirement to show the details for the currently selected row by using cell click event as follows.

Code Snippet[C#]:

   void dataGrid_CellClick(object sender, Syncfusion.Windows.Controls.Grid.GridCellClickEventArgs e)

        {

                int recordindex = this.dataGrid.Model.ResolveIndexToRecordPosition(e.RowIndex);

                dataGrid.Model.Table.ExpandDetailsViewAt(recordindex);

        }

 

 

 

And there is no direct support for hiding expand collapse cell. We have prepared a workaround to achieve your requirement. You can refer the following code snippet for this.

Code Snippet[C#]:

void ColumnWidths_LineSizeChanged(object sender, Syncfusion.Windows.Controls.Scroll.RangeChangedEventArgs e)

        {

            if (dataGrid.Model.Table.HasDetailsView)

            {

                if (e.NewSize == GridDataTableModel.ExpandCollapseCellWidth)

                {

                    if (dataGrid.ShowRowHeader && e.From == 1)

                        dataGrid.Model.ColumnWidths[1] = 0;

                    if (!dataGrid.ShowRowHeader && e.From == 0)

                        dataGrid.Model.ColumnWidths[0] = 0;

                }

            }

        }

 

 

We have prepared a sample based on your requirements and please find the sample in the following location.

Please let us know if you have any queries.

Regards,

Thangapriya

 



DetailsView_c812a6b9.zip


AS Ankesh Suresh Maradia December 4, 2013 01:59 PM UTC

On the click, i want to achieve two behaviors:

1) Expanding detail view on click, if it is closed. This is happening now.

2) Collapsing the detail view if i click on the row again, if the detail view is opened. Can you help with this?



SM Saravanan M Syncfusion Team December 9, 2013 09:54 AM UTC

Hi Ankesh,

 

Thanks for your update,

 

We have analyzed your query. You can collapse the detail view while click on the row if detail view opened by using IsDetailsViewExpanded API.

You can refer the below code snippet.

 

Codesnippet[C#]:

dataGrid.CellClick += dataGrid_CellClick;

 

void dataGrid_CellClick(object sender, Syncfusion.Windows.Controls.Grid.GridCellClickEventArgs e)

{

     int recordindex = this.dataGrid.Model.ResolveIndexToRecordPosition(e.RowIndex);

     var nodeentry = this.dataGrid.Model.View.Records[recordindex] as GridDataRecord;

     if (nodeentry.IsDetailsViewExpanded)

        dataGrid.Model.Table.CollapseDetailsViewAt(recordindex);

     else

        dataGrid.Model.Table.ExpandDetailsViewAt(recordindex);

}

 

 

Please let us know if this solution helps you,

 

Regards,

Saravanan.M


Loader.
Live Chat Icon For mobile
Up arrow icon