I'm trying to add a column to my XamDataGrid that is a XamComboEditor but can't seem to quite get how to do it simply. My XamDataGrid code is:
<igDP:XamDataGrid Grid.Row="0" HorizontalAlignment="Stretch" Name="dgPDUsers" DataSource="{Binding}" IsSynchronizedWithCurrentItem="True" HorizontalContentAlignment="Stretch" VerticalContentAlignment="Stretch"> <igDP:XamDataGrid.FieldLayouts> <igDP:FieldLayout Key="Expanded"> <igDP:FieldLayout.Fields> <igDP:Field Name="PDUserID" Label="User ID" Width="80" IsPrimary="True" IsScrollTipField="True" /> <igDP:Field Name="Name" Label="Name" Width="180" /> <igDP:Field Name="Clinics" Label="Clinics"> <igDP:Field.Settings> <igDP:FieldSettings EditorType="{x:Type igEditors:XamComboEditor}"> <igDP:FieldSettings.EditorStyle> <Style TargetType="{x:Type igEditors:XamComboEditor}"> <Setter Property="ItemsSource" Value="{Binding}" /> <Setter Property="DisplayMemberPath" Value="Name" /> <Setter Property="ValuePath" Value="ClinicID" /> </Style> </igDP:FieldSettings.EditorStyle> </igDP:FieldSettings> </igDP:Field.Settings> </igDP:Field> <igDP:Field Name="ActiveName" Label="Active" Width="80" /> </igDP:FieldLayout.Fields> </igDP:FieldLayout> </igDP:XamDataGrid.FieldLayouts> <igDP:XamDataGrid.FieldSettings> <igDP:FieldSettings CellClickAction="SelectRecord" LabelClickAction="SortByMultipleFields" AllowEdit="False" AllowRecordFiltering="True" /> </igDP:XamDataGrid.FieldSettings> <igDP:XamDataGrid.FieldLayoutSettings> <igDP:FieldLayoutSettings AutoGenerateFields="False" HighlightAlternateRecords="True" AllowDelete="False" FilterClearButtonLocation="RecordSelector" FilterRecordLocation="OnTopFixed" FilterUIType="Default" /> </igDP:XamDataGrid.FieldLayoutSettings> </igDP:XamDataGrid>
My page behind is handling the UserControl_Loaded event thusly:
private void UserControl_Loaded( object sender, RoutedEventArgs e ) { PDUser p = new PDUser(); List<PDUser> Users = p.SelfListAll(); this.dgPDUsers.DataContext = Users; } the PDUser object has your garden variety properties; int, string and ect. It also has a List<Clinic> property that is a list of Clinic object with a int ClinicID and string Name properties. Given that I am just learning WPF and the Infragistics library, what would be the most simple way toget my list of clinics in a combo box? As it stands now, the rows in the data grid show up with plus marks on the left side, and when you click on them they expand but nothing is there. I don't want that to show, just the combo boxes. Thanks.
private void UserControl_Loaded( object sender, RoutedEventArgs e ) { PDUser p = new PDUser(); List<PDUser> Users = p.SelfListAll(); this.dgPDUsers.DataContext = Users; }
the PDUser object has your garden variety properties; int, string and ect. It also has a List<Clinic> property that is a list of Clinic object with a int ClinicID and string Name properties.
Given that I am just learning WPF and the Infragistics library, what would be the most simple way toget my list of clinics in a combo box?
As it stands now, the rows in the data grid show up with plus marks on the left side, and when you click on them they expand but nothing is there. I don't want that to show, just the combo boxes.
Thanks.
Hello Mike,
I have created a sample application for you using the code snippet that you have posted. Since when you add a Field for a property that is a collection the XamDataGrid creates a hierarchy for it and displays it in a new FieldLaout, instead of adding a Field for the Clinics property I have added an UnboundField. The UnboundField uses that same FieldSettings and the Clinic Field in your xaml code. The only change that I have made is that I have changed the ItemsSource in order to bind to the Clinics property of the record that corresponds to current cell.
If you need any further assistance on the matter please dot hesitate to ask.
Sincerely,
Krasimir
Developer Support Engineer
Infragistics
www.infragistics.com/support
Krasimir,
Your sample was extraordinarily helpful, thank you.
I have a few other questions. First, the dropdown would never populate unless I added the following Setter property:
<Setter Property="SelectedIndex" Value="0" />
Why do you think that is? In your example the dropdowns were populated, and in mine they were blank until I added the setter.
The next question I have is how do I get the selected index to work? I want the first item in the list to be showing and I was thinking setting the selected index would do that, but all it did was make the data appear.
Thank you.
Mike.
I have been looking into your issue and I am not completely sure what the reason for not populating the data in the drop down might be. Would you please provide me with a sample application that demonstrates the behavior that you are describing or you can modify the sample application that I have sent you in order to replicate the issue?
Regarding the second question that you are having, I have logged this behavior with our developers in our tracking system, with an issue ID of 59404. I have also created a support ticket on your behalf with number CAS-80301-055865 in order to link the development issue to it so that you are automatically updated when a Service Release containing your fix is available for download.
Looking forward to hearing from you.
I am just checking if you require any further assistance on the matter.
I do need some help, and I am not sure of the best way to go about it. I'll post a code snippet and maybe I am doing something wrong syntactally you can see. Basically, I took your code example and used it and added a setter property for SelectedIndex. Here is the code, hopefully you can see what my error is. Just to summerize, no data was appearing in the drop downs until I added the SelectedIndex setter property. However, the size of the dropdown was appropriate for the number of rows that should have been showing. So if, for example, one row would have more items than another row, its dropdown was longer - but no data would appear. Then after adding the SelectedIndex setter property, the data started appearing, but no item was selected. Hopefully you can gain some insight into this issue from my code snippet.
Also, in the data grid's Initialized event, I am setting the data context with my list of objects:
private void PopulatePDUserList( ObservableCollection<PDUser> PDUserList ) { this.dgPDUsers.DataContext = null; this.dgPDUsers.DataContext = PDUserList; }
and in the data grid loaded event, I am setting the active record
private void SetActiveRecord( int SelectedRow ) { if ( this.dgPDUsers.Records.Count > 0 ) { this.dgPDUsers.Records[ SelectedRow ].IsSelected = true; this.dgPDUsers.ActiveRecord = this.dgPDUsers.Records[ SelectedRow ]; } }
<igDP:XamDataGrid Grid.Row="0" HorizontalAlignment="Stretch" Name="dgPDUsers" DataSource="{Binding}" IsSynchronizedWithCurrentItem="True" HorizontalContentAlignment="Stretch" VerticalContentAlignment="Stretch" Initialized="dgPDUsers_Initialized" Loaded="dgPDUsers_Loaded" SelectedItemsChanged="dgPDUsers_SelectedItemsChanged"> <igDP:XamDataGrid.FieldLayouts> <igDP:FieldLayout Key="Expanded"> <igDP:FieldLayout.Fields> <igDP:Field Name="PDUserID" Label="User ID" Width="65" IsPrimary="True"/> <igDP:Field Name="Name" Label="Name" Width="105" Visibility="Collapsed" IsScrollTipField="True" /> <igDP:Field Name="FirstName" Label="First Name" Width="105" /> <igDP:Field Name="LastName" Label="Last Name" Width="105"/> <igDP:UnboundField Name="Clinics" Width="150"> <igDP:UnboundField.Settings> <igDP:FieldSettings EditorType="{x:Type igEditors:XamComboEditor}" AllowEdit="True"> <igDP:FieldSettings.EditorStyle> <Style TargetType="{x:Type igEditors:XamComboEditor}"> <Setter Property="ItemsSource" Value="{Binding RelativeSource={RelativeSource Mode=FindAncestor, AncestorType={x:Type igDP:CellValuePresenter}}, Path=Record.DataItem.Clinics}" /> <Setter Property="DisplayMemberPath" Value="Name" /> <Setter Property="ValuePath" Value="ClinicID" /> <Setter Property="SelectedIndex" Value="0" /> </Style> </igDP:FieldSettings.EditorStyle> </igDP:FieldSettings> </igDP:UnboundField.Settings> </igDP:UnboundField> <igDP:UnboundField Name="Roles" Width="100"> <igDP:UnboundField.Settings> <igDP:FieldSettings EditorType="{x:Type igEditors:XamComboEditor}" AllowEdit="True"> <igDP:FieldSettings.EditorStyle> <Style TargetType="{x:Type igEditors:XamComboEditor}"> <Setter Property="ItemsSource" Value="{Binding RelativeSource={RelativeSource Mode=FindAncestor, AncestorType={x:Type igDP:CellValuePresenter}}, Path=Record.DataItem.Roles}" /> <Setter Property="DisplayMemberPath" Value="Name" /> <Setter Property="ValuePath" Value="RoleID" /> <Setter Property="SelectedIndex" Value="0" /> </Style> </igDP:FieldSettings.EditorStyle> </igDP:FieldSettings> </igDP:UnboundField.Settings> </igDP:UnboundField> <igDP:Field Name="LockedOut" Label="Locked Out" Width="90" /> <igDP:Field Name="ActiveName" Label="Active" Width="80" /> </igDP:FieldLayout.Fields> </igDP:FieldLayout> </igDP:XamDataGrid.FieldLayouts> <igDP:XamDataGrid.FieldSettings> <igDP:FieldSettings CellClickAction="SelectRecord" LabelClickAction="SortByMultipleFields" AllowEdit="False" AllowRecordFiltering="True" /> </igDP:XamDataGrid.FieldSettings> <igDP:XamDataGrid.FieldLayoutSettings> <igDP:FieldLayoutSettings AutoGenerateFields="False" HighlightAlternateRecords="True" AllowDelete="False" FilterClearButtonLocation="RecordSelector" FilterRecordLocation="OnTopFixed" FilterUIType="Default" /> </igDP:XamDataGrid.FieldLayoutSettings> </igDP:XamDataGrid>
Thank you for helping me with this.
Mike