Hello,
how can I bind to id fields while showing assocciated display text fields in the grid?
I managed the grid view and editing by styles, but unfortunately this seems like a hack.While the grid displays what I want, as soon as I enable features like filtering or grouping, the underlying id data is displayed again.
I thought about completely remove id binding and bind direct to the display text columns.But this raises other issues. Only think about two different records with the same display text.The reverse mapping to the actual database record would be impossible.
So, is there any built-in support to do this without using workarounds?
Thanks.
Thank you for your post. I have been looking into your question and if I understand correctly, you wish to bind some of the properties of the fields that you have defined in xaml, to your view model directly.
Since the fields are not part of the visual tree and also do not have a DataContext property, if you wish to create a binding to some of properties of the Field class, the Binding’s Source should be set.
If you would like to avoid setting the Source and bind to the DataContext of the XamDataGrid, I can suggest creating an attached property for the Field that is creating the binding. I have created a sample application you, that shows how you can implement this approach.
Please let me know if you need any further assistance on the matter.
Sincerely,
Krasimir, MCPD
Developer Support Supervisor - XAML
Infragistics
www.infragistics.com/support
Hello Krasimir,
thank you for this sample, it is very interesting.But sadly it does not really target my question...
I'll explain a bit more detailed using pseudo code.Goal is to get a column where one can select a user.Displayed will be the users name, but stored the users id.The name is provided by the models row data along with the id.When the id is changed, the userName property in the model is updated.
Keep in mind that you cannot use the comboboxes content to provide the display texts.The combobox value source will be only a filtered set of all available id/displaytext values.
Thank you.
Assume the following data model :
class User int userId; string userName;
class TimeBooking int bookingId; DateTime bookingDate; int userId; string userName;
class TimeBookingRows : ObservableCollection<TimeBooking>
class ViewModel TimeBookingRows dataRows; List<User> users;
Xaml:<igWPF:XamDataGrid DataSource="{Binding dataRows}"> <igWPF:Field Name="bookingDate" /> <igWPF:Field Name="userId" DisplayPath="userName"> <SomeComboBoxControl DataSource="{Binding users}" DataPath="userId" DisplayPath="userName" /> </igWPF:Field>
Thank you for your reply and the clarification on your requirement. I have been looking into your scenario and you can use the XamComboEditor to implement it. You can use the Field’s Settings of the UserID field, to set the editor to be a XamComboEditor and using an EditorStyle, you can bind the ItemsSource of the XamComboEditor to the Users property of your view model. Also you can use the style to set the DisplayMemeberPath and ValuePath of the XamComboEditor, which will allow you display the UserName in the UserID field. I have created a sample application for you, that shows how you can implement this approach.
thank you for this sample, but I know this very well.In fact this was my first try at all to solve the problem.
As I wrote before, the combobox approach lacks in one situation.The data source of the combobox cannot contain all possible available users.
The real life application is much more complex and data intensive.The model contains ProjectGroups, each one containing thousands of Projects with each of them hundrets of sub-projects.I think you'll understand that I cannot load a million of records in the datasource of the combobox.In real life, for example the sub-projects combobox will only contain the records contained within the currently selected project within the same row.
But for making things easier, I've slightly modified the samle you provided.The user number 7 is not contained in the combobox, but it is displayed.I've added the UserName property as a separate column to make thinks clear.In fact, it should be only one column. But instead of the id 7 there has to be displayed User7.
So, the DisplayText binding must be assigned to the field directly.
Thank you for revisiting this thing.
Thank you for your reply. I am very glad that you have managed to fix the issue that you were having. Please le t me know if I can assist you with anything else
Hi Krasimir,
meanwhile I went another way to fit my needs.It turned out that the approach from the thread Edit custom-object field using combobox selection in XamDataGrid works much better for me.
I am just checking if you require any further assistance on the matter.
Thank you for your reply and the modified sample. I have been looking into your scenario and in order to be able to change the display value of the cell that has no corresponding item in the ItemsSource of the XamComboEditro, what you can do is using the ValueToDisplayTextConverter property. You can create a class that derives from IValueConverter and in the converter to implement the logic for the values that are not in the list. You can check that by using the parameter of the Convert method, which is the XamComboEditor and check whether the SelectedItem property has a value. In order to be able to get the converter firing when the selected item is initialized, you can add an EventSetter for the Loaded event of the XamComboEditor and set the ValueToDispalyTextConverter in the event handler. I have modified the sample you have attached to shows how you can implement this approach.