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 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.
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 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.