Hello,
I would like to create a datagrid that provides a list of States as a XamComboEditor and another that provides a list of Cities within a State as a XamComboEditor. I am not sure how to accomplish this. Basically I would like the selected item of the States to filter the ItemsSource of my Cities combobox. Any thoughts?
Hi,
There are probably a couple of different ways to implement this functionality in your application.
Solution:
2. Check to see if the cell entering edit mode belongs to the City Field.
3. If so, apply a filter to the collection that contains city information.
I am attaching a sample as a proof-of-concept. Since you did not state the version of NetAdvantage for WPF you are using in your application, I used the latest and greatest 8.2. If you do not have 8.2, you will have to replace the references in the project
There are other ways to implement this functionality based on your data source. If your State object expose a nested collection of City objects, you can use a RelativeSource binding to retrieve the Cities in a particular State. For example, the Field that contains the City information would use the following EditorStyle:
<Style TargetType="{x:Type igEditors:XamComboEditor}"> <Setter Property="ItemsSource" Value="{Binding RelativeSource={RelativeSource Mode=FindAncestor, AncestorType={x:Type igDP:DataRecordPresenter}}, Path=DataRecord.DataItem.State.Cities}" /> <Setter Property="DisplayMemberPath" Value="CityName" /></Style>
Here is some source code that will help you populate the ComboBox with default set of data
XAML Code:
<Grid x:Name="root"> <igDP:XamDataGrid Margin="142,66,8,12" Name="xamDG" DataSource="{Binding}"> <igDP:XamDataGrid.Resources> <XmlDataProvider x:Key="PrioritiesXml"> <x:XData> <priorities xmlns=""> <priority text="High" id="0" /> <priority text="Normal" id="2" /> <priority text="Low" id="1" /> </priorities> </x:XData> </XmlDataProvider> <Style x:Key="PriorityFieldStyle" TargetType="{x:Type igEditors:XamComboEditor}"> <Setter Property="ItemsProvider"> <Setter.Value> <igEditors:ComboBoxItemsProvider ItemsSource="{Binding Source={StaticResource PrioritiesXml}, XPath=/priorities/priority}" DisplayMemberPath="@text" ValuePath="@id"/> </Setter.Value> </Setter> </Style> <igEditors:ComboBoxItemsProvider x:Key="StatusItemsProvider" /> <Style x:Key="StatusFieldStyle" TargetType="{x:Type igEditors:XamComboEditor}"> <Setter Property="ItemsProvider" Value="{StaticResource StatusItemsProvider}" /> </Style> </igDP:XamDataGrid.Resources> <igDP:XamDataGrid.FieldLayouts> <igDP:FieldLayout> <igDP:FieldLayout.Fields> <igDP:Field Name="Name" Label="Task Name"> <igDP:Field.Settings> <igDP:FieldSettings AllowEdit="False" CellWidth="180" LabelWidth="180" /> </igDP:Field.Settings> </igDP:Field> <igDP:Field Name="State" Label="Status"> <igDP:Field.Settings> <igDP:FieldSettings EditorStyle="{StaticResource StatusFieldStyle}" CellWidth="150" LabelWidth="150" /> </igDP:Field.Settings> </igDP:Field> <igDP:Field Name="PriorityLevel" Label="Priority"> <igDP:Field.Settings> <igDP:FieldSettings EditorStyle="{StaticResource PriorityFieldStyle}" /> </igDP:Field.Settings> </igDP:Field> </igDP:FieldLayout.Fields> </igDP:FieldLayout> </igDP:XamDataGrid.FieldLayouts> </igDP:XamDataGrid> </Grid>
And the Code-Behind source:
public Window1() { InitializeComponent(); ComboBoxItemsProvider statusProvider = this.xamDG.TryFindResource("StatusItemsProvider") as ComboBoxItemsProvider; if (statusProvider != null) { statusProvider.ItemsSource = new ComboBoxDataItem[ { new ComboBoxDataItem(ProgressState.Ready, "Ready"), new ComboBoxDataItem(ProgressState.InProgress, "In Progress"), new ComboBoxDataItem(ProgressState.PendingCompletion, "Pending Completion"), new ComboBoxDataItem(ProgressState.Complete, "Complete") }; ComboBoxDataItem a = new ComboBoxDataItem(); } base.DataContext = new Task[ { new Task { Name="Deliver Payload", State = ProgressState.Ready, PriorityLevel = 0 }, new Task { Name="Initialize Instruments", State = ProgressState.Complete, PriorityLevel = 2 }, new Task { Name="Analyze Heat Sensor Log", State = ProgressState.InProgress, PriorityLevel = 2 }, new Task { Name="Report Temperature Readings", State = ProgressState.PendingCompletion, PriorityLevel = 1 } }; } public class Task { public string Name { get; set; } public int PriorityLevel { get; set; } public ProgressState State { get; set; } } public enum ProgressState { Complete, InProgress, PendingCompletion, Ready }
There are also examples in the XamFeatureBrowser that you can look at for some more help.
Hope this will help you.
Sorry but that was not what i mean.My properties "tenMileRuns" and "gameNames", needs to be display'd in a combobox.Pseudo code:Public class Person{ public string Name{get;set;} public int age{get;set;} public DateTime[ tenMileRuns {get;set;} public List<string> gameNames {get;set;}}public class ShowPersons : Window{ public ShowPersons() { List<Person> persons = new List<Person>() { new Person(){Name = "John", age = 20, tenMileRuns = new DateTime[, gameNames = new List<string>{"LA","NY","CA", "MI"}, new Person(){............... AND SO ON }; /// DATAGRID and FIELD definitions dataGrid.DataSource = persons; }}
The XamDataGrid will not be able to insert the values directly in the ComboBoxes. This will be a form of hierarchy. You need to set the datasource of the ComboBoxes the collections of data - in your case : gameNames and tenMileRuns. You can see that i the XamFeatureBrowser -> Control Composition -> XamComboBoxEditor in DataRecord Cells.