Hi,
I have a class
class Test{ string name; List<string> values}
And I have a Dictionary <int, Test>. Now I have to bind this data to a xamdatagrid such that I have 2 columns, one with the name and other with the values. The number of rows created for every Test object should be equivalent to the number of values in the List.
Is it possible to achieve this?
Thanks
Hello,
You can use an unbound field and set the CellValuePresenter Style to re-template the column which contains the list. For example you can place a list box in the cell to display all the values.
Please see attached sample.
Sincerely,
Valerie
Developer Support Engineer
Infragistics
www.infragistics.com/support
Do you have any other questions on this matter?
Sincerely,ValerieDeveloper Support Engineer Infragisticswww.infragistics.com/support
I know this is after quite a while. But I looked into the above example and I have a question.
In the following piece of code "Convert(Object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)",
I want to know how the converter is able to receive KeyValuePair<int, Test> object in the parameter "value" when param == "Name".
I am declaring the fields in fieldLayout dynamically in code and not able to simulate it.
Appreciate the help. :)
I thought some more information can help here. I am actually declaring my fields in code as follows.
IValueConverter conv = new MyConverter();
myGrid.FieldLayoutSettings.AutoGenerateFields = false; FieldLayout fl = new FieldLayout(); Field f = new Field("Key"); fl.Fields.Add(f); f = new Field() { Label = "Name", BindingType = BindingType.Unbound, Converter = conv, ConverterParameter = "Name" };fl.Fields.Add(f);
myGrid.FieldLayouts.Clear(); myGrid.FieldLayouts.Add(fl);
When I try to run the program, it fails in the converter. The "value" parameter of the converter shows up null.
Hello Viswanath,
You need to set the binding on the unbound field, for example:
UnboundField NameField = new UnboundField();
NameField.Label = "Name";
MyConverter conv = new MyConverter();
Binding binding = new Binding();
binding.Converter = conv;
binding.ConverterParameter = "Name";
NameField.Binding = binding;
Software Developer
Infragistics Inc
Hi Valerie,
Thank you for the response. The suggested method works. But, I am getting the following alert when I try to use UnboundField.
Unbound field is obsolete: Use Field (or one of its editor specific derived classes) with the new BindingType property set to 'Unbound' or 'UseAlternateBinding' instead. The new 'AlternateBinding' and 'AlternateBindingRetentionMode' properties replace all the UnboundFields 'Binding...' properties.
Can you also tell me, how to define the third column in the example (the one with lists in each cell) programmatically?
Since in this case we are re-templating the CellValuePresenter and need to create a control template the best method to do this is to create the CellValuePresenterStyle in XAML and then attach it to the field in code behind. For example:
XAML:
<Window.Resources>
<local:MyConverter x:Key="Conv"/>
<Style x:Key="style1" TargetType="{x:Type igDP:CellValuePresenter}">
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type igDP:CellValuePresenter}">
<ListBox ItemsSource="{Binding DataItem.Value,
Converter={StaticResource Conv},ConverterParameter=Test}" />
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
</Window.Resources>
C#:
UnboundField ValuesField = new UnboundField();
Style style = (Style) this.Resources["style1"];
FieldSettings fs = new FieldSettings();
fs.CellValuePresenterStyle = style;
ValuesField.Settings = fs;
I had missed your earlier question on the Unbound field. In 14.2 changes were made wherein any field can be configured to be an unbound field by setting the Fields binding type to Unbound rendering the Unbound field obsolete. To learn more about these changes please see: http://help.infragistics.com/doc/WPF/2016.1/CLR4.0/?page=Whats_New_in_2014_Volume_2.html.