This thread looks to be a little on the old side and therefore may no longer be relevant. Please see if there is a newer thread on the subject and ensure you're using the most recent build of any software if your question regards a particular product.
This thread has been locked and is no longer accepting new posts, if you have a question regarding this topic please email us at support@mindscape.co.nz
|
Many of the data types that we allow editing and creation within a datagrid are lightspeed entities, and as such much of the data is stored in the form of entity IDs. For example, a MeasurementInterval object has a PathId property, which references the instance of the Path object that the measurement interval exists on. The issue is then that we want to allow the user to select the path by name, rather than by ID. I know we can accomplish this by a series of ValueConverters; one to convert the selected Id value to the Path.Description text property for the DisplayTemplate and another to set the PathId value for the EditorTemplate (based on the Path.Id of the selected item from an List I'm curious if there's any (planned?) provision for a directly embedded combo box in a datagrid, which would allow the user to set the "Selected Value Path"-- eg, if I have a list of Path objects populating a combobox's itemssource, the SelectedValue can be set to the "Id" property of the selected Path object, while the "Display Value Path"--the property of the selected object to display-- can be set to the "Description" property. |
|
|
From the sound of it, what you envisage is still just using a ComboBox control as the edit template, but with a way to pass through a SelectedValuePath and a DisplayMemberPath from the column so you don't need to repeat the template for each association. Is that correct? If so, there's no immediate plans for this. But it sounds like a handy feature, and we will try to take a look at it. (Also, just to confirm, this is not blocking you -- you have an approach for implementing it in the Interval/Path case, you were just hoping for something more reusable, correct?) |
|
|
Yes, you are correct in both counts. We can do it via repeated templates and some converters, but a more reusable approach would be preferable in the long run. |
|
|
Okay, the good news is that you can to some extent do this already. The trick is to specify the editor via a PropertyEditor (in the DataGrid.Editors collection) rather than directly on the column. PropertyEditor has an EditContext property, which gets passed across to the editor template. So you can write a template like:
Two things to note:
Now of course we need to configure this editor template with the appropriate settings for any particular association. To do this, use the Editors collection, provide a PropertyEditor object, and set its EditContext property:
(Here AssociationEditInfo is a trivial class with two properties, NameProperty and ValueProperty, to hold the names of the desired display and value members. You might want to think of better names -- all these 'properties' get a bit confusing!) Notice that we are able to reuse the same editor template to display customers (by FullName) and paths (by Description) by varying the EditContext. Your EditContext can be as simple or as complex as you need depending on what info you need to vary in the editor template. For more info, the DataGrid shares a lot of its editor infrastructure with the PropertyGrid control, and some of the help and how-to topics under Property Grid may be helpful, in particular Help Topics > Property Grid > Object Model (though it doesn't go into detail on this particular technique); also some of our blog and forum posts on the Property Grid control contain much more detailed info and examples. But hopefully this will be enough to get you started! (By the way, don't get hung up on this, but a handy tip if you find yourself using EditContexts a lot is that you can use markup extensions to make the syntax less verbose e.g. |
|
|
Thanks, that approach is more elegant than what I had in mind at first. Note that I had to add a parameter to the described AssociationEditInfo to pass in the desired ItemsSource for the combo box. |
|