In my last question, I asked about dynamically added layouts. Turns out I didnt need to and thanks to Rob, he got me going. Now I have another design modification where they want to add lookup data to a specific fields so this means I need to add a dropdown to the field(5 fields in all so 5 dropdowns) in the grid. Can this be done dynamically? Or do I need to produce a specialized template of some sort to call?
Constraints is I have various data sources that utilize the same grid so I need to be able to programmatically alter the FieldLayout based on the datasources. I suppose if worse comes to worse I can add another grid to handle the specialized nature of this one datasource and just invis or vis the grids as needed depending on whether or not the datasource is being used. Not sure I want to go that route though...
I was able to get the comboboxes working... a section of code had to be retooled in the onFieldLayoutInitialized event. an IF statement was handled wrong and the swithc statement was never reached.
One thing I do not understand is how do i bind the selected value path to the underlying cell/field?
*edit*
Acutally it doesnt work... the combo box can change value when using the vertical scrollbar....
attached is my test project.
Thank you for the links... somewhat helpful.
My grid does not have defined fields. The fields are autogenerated based on the supplied data source. Below is the XAML for my grid:
<igWPF:XamDataGrid x:Name="GrdMaint" Margin="10" Grid.Row="3" Grid.Column="0" Grid.ColumnSpan="2" DataSource="{Binding Source={StaticResource cvsDataGrid}}" BorderBrush="Black" BorderThickness="1" HorizontalAlignment="Left" VerticalAlignment="Top" Theme="Office2k7Blue" GroupByAreaLocation="None" FieldLayoutInitialized="GrdMaint_OnFieldLayoutInitialized"> <igWPF:XamDataGrid.FieldSettings> <igWPF:FieldSettings AllowRecordFiltering="True" FilterOperandUIType="TextBox"/> </igWPF:XamDataGrid.FieldSettings> <igWPF:XamDataGrid.FieldLayoutSettings> <igWPF:FieldLayoutSettings HighlightAlternateRecords="True" FilterClearButtonLocation="FilterCell" FilterRecordLocation="OnTop" FilterUIType="FilterRecord" AutoGenerateFields="True" /> </igWPF:XamDataGrid.FieldLayoutSettings> </igWPF:XamDataGrid>
My window resource :
<Window.Resources> <CollectionViewSource x:Key="cvsDataGrid" Source="cvsDataGrid"/> <CollectionViewSource x:Key="cvsTaskList" Source="cvsTaskList"/> <CollectionViewSource x:Key="cvsPickList1" Source="cvsPickList1" /> <CollectionViewSource x:Key="cvsPickList2" Source="cvsPickList2" /> <CollectionViewSource x:Key="cvsPickList3" Source="cvsPickList3" /> <CollectionViewSource x:Key="cvsPickList4" Source="cvsPickList4" /> <Style x:Key="EditableColumn" TargetType="{x:Type igWPF:CellValuePresenter}"> <Style.Triggers> <DataTrigger Binding="{Binding RelativeSource={RelativeSource Self}, Path=IsEditingAllowed}" Value="True"> <Setter Property="Background" Value="LightYellow"/> </DataTrigger> </Style.Triggers> </Style> <Style x:Key="DropDownPicker1" TargetType="{x:Type igWPF:CellValuePresenter}"> <Setter Property="Template"> <Setter.Value> <ControlTemplate TargetType="{x:Type igWPF:CellValuePresenter}"> <ig:XamComboEditor x:Name="cboPickList1" ItemsSource="{Binding Source={StaticResource cvsPickList1}}" DisplayMemberPath="DisplayLabel" SelectedValuePath="ProductLineID" /> </ControlTemplate> </Setter.Value> </Setter> </Style> <Style x:Key="DropDownPicker2" TargetType="{x:Type igWPF:CellValuePresenter}"> <Setter Property="Template"> <Setter.Value> <ControlTemplate TargetType="{x:Type igWPF:CellValuePresenter}"> <ig:XamComboEditor x:Name="cboPickList1" ItemsSource="{Binding Source={StaticResource cvsPickList2}}" DisplayMemberPath="DisplayLabel" SelectedValuePath="ProductLineID" /> </ControlTemplate> </Setter.Value> </Setter> </Style> ...
In my code behind i want to do this:
private void GrdMaint_OnFieldLayoutInitialized(object sender, FieldLayoutInitializedEventArgs e) { foreach (Field fld in e.FieldLayout.Fields) { fld.Settings.AllowEdit = false; if (_hideColumns != null && _hideColumns.Any()) { if (_hideColumns.Contains(fld.Name)) fld.Visibility = Visibility.Collapsed; } if (_editColumns == null || !_editColumns.Any()) continue; if (!_editColumns.Contains(fld.Name)) continue; fld.Settings.AllowEdit = true; fld.Settings.CellValuePresenterStyle = Resources["EditableColumn"] as Style; // if this is CE then we need to add combo box to the fields... if (_cboColumns == null || !_cboColumns.Any()) continue; if (SvcModel.Equals("CE")) { switch (fld.Name) { case "ProductLineName": fld.Settings.CellValuePresenterStyle = Resources["DropDownPicker1"] as Style; break; case "TradeElement": //fld.Settings.CellValuePresenterStyle = Resources["DropDownPicker2"] as Style; break; case "ActivityCode" : fld.Settings.CellValuePresenterStyle = Resources["DropDownPicker3"] as Style; break; case "LaborType" : //fld.Settings.CellValuePresenterStyle = Resources["DropDownPicker4"] as Style; break; } } } }This is so I can dynamically define the layout... and when I load a particular datasource the grid will reflect the correct layout. However none of the combobox show up. Any ideas?
On a side note editing this message then posting wiped out some of the content.... I have had to re-enter it again.
Hi,
Thank you for your reply. I have been looking into your requirement and you can see how Krasimir has added a XamComboEditor in a field of the XamDataGrid:
http://es.infragistics.com/community/forums/t/63525.aspx
Also you could look into the following link from our online documentation how to use our new ComboBoxField in vol. 14.2:
http://help.infragistics.com/doc/WPF/2014.2/CLR4.0/?page=xamDataPresenter_Configuring_Specific_Editor_Fields.html
Let me know, if you need any further assistance on this matter.
?? I dont know where you get record filtering out of what I am asking for. You missed the mark entirely.
I need to create a combo/dropdown in the grid for cells of 5 columns to allow the users to be able to pick values for the cell they are editing. So each of those cells will have a combobox. My guess is that I need to create a style that has a combobox and associate it with a field and have a collectionviewsource bound to the combobox. I havent figured out how to do this. THis is what I need help with....
thanks
Thank you for your post. I have been looking into your requirement and it seems that you need to enable record filtering. For more information about record filtering you could look into the following link from our online documentation:
http://help.infragistics.com/doc/WPF/2014.2/CLR4.0/?page=xamDataPresenter_About_Record_Filtering.html
The link below shows how to activate it:
http://help.infragistics.com/doc/WPF/2014.2/CLR4.0/?page=xamDataPresenter_Enable_Record_Filtering.html