Your Privacy Matters: We use our own and third-party cookies to improve your experience on our website. By continuing to use the website we understand that you accept their use. Cookie Policy
115
XamDataGrid , XamComboBox and generic KeyValuePair
posted

Hey. I have got a XDG with a field of type KeyValuePair<Guid, string>.

The DataSource is xml, which causes the problem, that a string (the value of the xml element) needs to be parsed into the KeyValuePair. How do i tell the XDG to use an appropriate TypeConverter?

Would be great, if i could provide my own TypeConverter, because then i could put just the Guid into the xml and select the correct Pair from another Dictionary.

The particular application is that i display a xamComboBox for the user which shows only the values. Since i need to create the fields of the XDG dynamically, i add the Combobox by looping over the Fields and adjust the style as follows.

 

Dictionary<Guid, string> myDictionary = ...
foreach (var field in xamDataGrid1.RecordManager.Current.FieldLayout.Fields)
            {
                if (field.DataType == typeof(KeyValuePair<Guid, string>))
                {
                    Style style = new Style(typeof(XamComboEditor));

                    style.Setters.Add(new Setter(XamComboEditor.ItemsSourceProperty, myDictionary));
                    style.Setters.Add(new Setter(XamComboEditor.DisplayMemberPathProperty, "Value"));

                    field.Settings.EditorType = typeof(XamComboEditor);
                    field.Settings.EditorStyle = style;
                }
            }

That works fine, the problem is that the DataSource is xml and the Elements that describe the Key (or KeyValuePairs if necessary) are not used... Thanks for help.

 

EDIT

Ok, actually i put the xml first into a DataSet which I bind than to the XDG. So the problem is not how to tell the XDG the right TypeConverter to intepret the element of the xml, but how to tell this to the DataSet. So this is probably not the right forum. Sorry for that, however maybe someone knows the answer?!