Hi,
I need to create a ComboBox-like column in a SfDataGrid, only the drop down has to present not a list of items, rather an user defined tree structure which has an arbitrary composition, similar to the shown on the picture.
Could you, please, help me, how can achieve this?
Best regards
Alexander
Hi Alexander Tashkov,
We have checked the feasibility to achieve your requirement. By default, the combo box drop-down displays the items from its ItemsSource. So, there are no possibilities to display the tree structure in the combo box drop-down as you requested. Our SfDataGrid has GridTemplateColumn with this you can load any WPF control in the display mode for all columns by setting CellTemplate and EditTemplate properties. For more information related to GridTemplateColumn, please refer to the below user guide documentation link,
UG Link: https://help.syncfusion.com/wpf/datagrid/column-types#gridtemplatecolumn
You can customize this as your own based on your requirement.
regards,
Dhanasekar M.
Hi Dhanasekar,
Sorry for answering a little late.
Thank you for your reply.
As to my understanding, GridTemplateColumn is not what I would need in that case - I do not want to display the tree structure in the cell (i.e. by setting a SfTreeGrid in it). In the cell I need to present the object, that the user selects from a tree structure. A simple text column would be fine, I only cannot figure out how to let the user select a single object out of the respective tree structure.
Any ideas?
Best regards,
Alexander
Alexander
Your requirement to “Change the cell content depending on the selected item present in the tree” will be achievable by resetting the underlying property as shown below.
this.listView.SelectionChanged += OnListViewSelectionChanged; { // Resetting the SfDataGrid's cell content depending on the selected listview item. (this.sfDataGrid.DataContext as ViewModel).OrderDetails[0].ShipName = (e.AddedItems[0] as Orders).ShipName.ToString(); } |
Here, we have prepared
the sample with the ListView and SfDataGrid along with the video reference,
please have a look at this.
If this post is helpful, please consider Accepting it as the solution so that other members can locate it more quickly.
Hi Dhanasekar,
Thank you very much for the idea. It works and I will implement it in my case.
Another possibility would be to put the structure in a context menu an let the user pick one option from it. I just could not figure out how to get the cell the user right-clicked on.
And still - I think, a much more elegant solution that would cover many different scenarios would be if the DataGrid had a sort of "GridTreeViewColumn" type of columns... I suppose, I will have to post a feature request for that and hope it would be accepted some time in the future.
Best regards,
Alexander
Alexander,
We have checked the feasibility to achieve your requirement. In that, the context menu only display’s the MenuItem that is present in it. There is no possibility to populate the tree structure inside the context menu as you requested. As we mentioned earlier, the SfDatagrid contains the GridTemplateColumn to achieve this kind of requirement. You can load whatever control that you need by using the CellTemplate and EditTemplate of the GridTemplateColumn. Here, we have prepared the sample and video demo for your reference, please have a look at this.
If this post is helpful, please consider Accepting it as the solution so that other members can locate it more quickly.
Hi Dhanasekar,
And - thanks again. This sample is really super-close to what I have imagined. Will take a closer look at it immediately.
Regarding the context menu. I probably did not explain it right. I meant - a context menu can be created with menu items, sub-menu items etc., that resemble the tree structure. And I did it as a proof of concept. The problem was - I could not figure out how to get the cell of the SfDataGrid the user has right-clicked on. How can I get that information programmatically?
Best Regards,
Alexander
Alexander,
Your requirement to “get the current cell while performing the right click” will be achievable by using the SfDataGrid.CurrentCellActivated event as shown in the below code snippet,
this.sfDataGrid1.CurrentCellActivated +=
OnSfDataGrid1CurrentCellActivated; { // Get the current cell var currentCell = this.sfDataGrid1.CurrentCell;
// Get the row index value var rowIndex = e.DataRow.RowIndex; //Get the column index value var columnIndex = e.DataColumn.ColumnIndex; //Get the cell value var cellValue = this.sfDataGrid1.View.GetPropertyAccessProvider().GetValue(e.DataRow.RowData, e.DataColumn.GridColumn.MappingName); } |
Also, if you need to get the current cell-related details and cell values please
refer to the below user guide documentation,
UG Link:
https://help.syncfusion.com/windowsforms/datagrid/selection#get-the-current-cell,
If this post is helpful, please consider Accepting it as the solution so that other members can locate it more quickly.