Hi,
When I add a new record to my grid, that record is not selectable again, yet the records that were filled upon loading the grid are selectable. There is a protected property call IsSelectable. My old records return true for this property, but my new records return false after I have added the record. Specifically, when the RecordUpdating event is fired the rnew ecord is selectable, when the RecordUpdated event is fired that record is no longer selectable (the property returns false). The documentation is quite sparse for this property, "Returns true only if the record can be selected" is the extent of the documentation. What determines the selectabiity of a record? Why would the initial records be selectable but the added records not be?
Thanks for your help!
TJ
Hi Joe,
Thanks for your quick response!
I will show you what I am doing. I have an AddRecord row fixed at the top. It consists of two visible fields and two collapsed fields. The first field is implemented as a ComboBox (using XAML virtually identical to code in the documentation). When I select an item in the combobox (which corresponsds to the ControlName field, I then fill in the rest of the fields, and set the other visible field as active in case the user wants to change it:
{
ControlRecordWithControlTypeName item = (sender as ComboBox).SelectedItem as ControlRecordWithControlTypeName; if (item == null)return; _addRecord.Cells["ControlName"].Value = item.ControlName;_addRecord.Cells["ControlID"].Value = item.ControlID; _addRecord.Cells["ControlTypeName"].Value = item.ControlTypeName;_addRecord.Cells["ControlTypeID"].Value = item.ControlTypeID;_addRecord.Cells["ControlTypeName"].IsActive = true;
if (item == null)
_addRecord.Cells["ControlName"].Value = item.ControlName;
_addRecord.Cells["ControlTypeName"].Value = item.ControlTypeName;
}
When I hit Enter, and the record is updated the IsSelectable property changes from true to false between the RecordUpdating event and the RecordUpdated event.
For completeness I will show you the XAML for the grid (I will leave out the fields, they all have AllowEdit=true and AllGroupBy=false:
<grid:XamDataGrid Grid.Row="1" HorizontalAlignment="Stretch" VerticalAlignment="Stretch" Margin="20,30,20,2" Name="dgControls" MinWidth="400" MinHeight="100" DataSource="{Binding Source={StaticResource CRWithCTName}}" InitializeRecord="dgControls_InitializeRecord" IsEnabled="True" InitializeTemplateAddRecord="dgControls_InitializeTemplateAddRecord" AutoFit="True" IsNestedDataDisplayEnabled="False" RecordActivated="dgControls_RecordActivated" RecordDeactivating="dgControls_RecordDeactivating" UpdateMode="OnUpdate" RecordUpdating="dgControls_RecordUpdating" RecordUpdated="dgControls_RecordUpdated">
<grid:XamDataGrid.FieldLayoutSettings>
<grid:FieldLayoutSettings AllowAddNew="True" AllowDelete="True" AddNewRecordLocation="OnTopFixed" HighlightAlternateRecords="True" DataRecordSizingMode="SizedToContentAndIndividuallySizable" AutoGenerateFields="False" SelectionTypeRecord="Single"/>
</grid:XamDataGrid.FieldLayoutSettings> ... field information...
</grid:XamDataGrid.FieldLayoutSettings>
... field information...
The RecordActivate and Update events are only used to observe the state of the record and don't perform any function.
The InitializeTermplateAddRecord event does the following:
if (_addRecord != null) { _addRecord.Cells["ControlName"].EditAsType = typeof(string); _addRecord.Cells["ControlName"].EditorStyle = null; } _addRecord = e.TemplateAddRecord; //cboControlNameEditor is the combobox for column one. It is almost a direct copy of the example in your doumentation _addRecord.Cells["ControlName"].EditorStyle = FindResource("cboControlNameEditor") as Style;
_addRecord.Cells["ControlName"].EditAsType = typeof(string); _addRecord.Cells["ControlName"].EditorStyle = null;
_addRecord.Cells["ControlName"].EditorStyle = null;
_addRecord = e.TemplateAddRecord;
//cboControlNameEditor is the combobox for column one. It is almost a direct copy of the example in your doumentation
_addRecord.Cells["ControlName"].EditorStyle = FindResource("cboControlNameEditor") as Style;
I hope this gives you enough information.
Thanks for your help,
Joe,
I tried to eliminate any extraneous code. The current behavior is once I add a new row and select out of it, I can never select it again. Below is the XAML, then the C#. I am not including the App file, since that class is empty. the name of this app (and its namespace is Tester).
Thanks, TJ
<Window x:Class="Tester.Window1"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:src="clr-namespace:Tester"
xmlns:grid="http://infragistics.com/DataPresenter"
xmlns:igEditors="http://infragistics.com/Editors"
Loaded="Window_Loaded"
Title="Window1" MinHeight="300" MinWidth="300">
<Window.Resources>
<src:CRWithCTName x:Key="CRWithCTName"/>
<src:ControlCacheTemp x:Key="ControlCacheTemp"/>
x:Key="cboControlNameEditor">
<Setter Property="EditTemplate">
<Setter.Value>
<ControlTemplate TargetType="{x:Type igEditors:XamTextEditor}">
<StackPanel>
<ComboBox x:Name="cboComboboxEditor" BorderThickness="0" Background="Transparent" VerticalContentAlignment="Top"
Foreground="{Binding RelativeSource={RelativeSource TemplatedParent}, Path=(TextElement.Foreground)}"
IsEditable="True" Loaded="cboComboboxEditor_Loaded" SelectionChanged="cboComboboxEditor_SelectionChanged"
SelectedValuePath="ControlID" DisplayMemberPath="ControlName" ItemsSource="{Binding Source={StaticResource ControlCacheTemp}}"
SelectedItem="{Binding RelativeSource={RelativeSource TemplatedParent}, Path=Text, Mode=TwoWay}"
Text="{Binding RelativeSource={RelativeSource TemplatedParent}, Path=Text, Mode=TwoWay}">
<ComboBox.Resources>
<Style TargetType="Popup">
<Setter Property="TextElement.Foreground"
Value="{DynamicResource {x:Static SystemColors.WindowTextBrushKey}}" />
</Style>
</ComboBox.Resources>
</ComboBox>
</StackPanel>
</ControlTemplate>
</Setter.Value>
</Setter>
</Window.Resources>
<Grid>
<grid:XamDataGrid HorizontalAlignment="Stretch" VerticalAlignment="Stretch" Margin="20,30,20,2" Name="dgControls" MinWidth="400" MinHeight="100"
DataSource="{Binding Source={StaticResource CRWithCTName}}" IsEnabled="True" AutoFit="True"
InitializeTemplateAddRecord="dgControls_InitializeTemplateAddRecord" IsNestedDataDisplayEnabled="False">
<grid:FieldLayoutSettings AllowAddNew="True" AllowDelete="True" AddNewRecordLocation="OnTopFixed" HighlightAlternateRecords="True"
DataRecordSizingMode="SizedToContentAndIndividuallySizable" AutoGenerateFields="False" >
</grid:FieldLayoutSettings>
<grid:XamDataGrid.FieldLayouts>
<grid:FieldLayout>
<grid:FieldLayout.Fields>
<grid:Field Name="ControlID" Visibility="Collapsed">
<grid:Field.Settings>
<grid:FieldSettings AllowEdit="True" AllowGroupBy="False"/>
</grid:Field.Settings>
</grid:Field>
<grid:Field Name="ControlName" Visibility="Visible" Label="Control Name" Column="1">
<grid:Field Name="ControlTypeID" Visibility="Collapsed">
<grid:Field Name="ControlTypeName" Visibility="Visible" Label="Control Type Name" Column="2">
</grid:FieldLayout.Fields>
</grid:FieldLayout>
</grid:XamDataGrid.FieldLayouts>
</grid:XamDataGrid>
</Window>
using System;
using System.Collections.Generic;
using System.Collections;
using System.Collections.ObjectModel;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using Infragistics.Windows.DataPresenter.Events;
using Infragistics.Windows.DataPresenter;
using Infragistics.Windows.Editors;
using Infragistics.Windows.Commands;
//using ControlDataCache;
using System.ComponentModel;
/// <summary>
/// Interaction logic for Window1.xaml
/// </summary>
public partial class Window1 : Window
DataRecord _addRecord = null;
InitializeComponent();
public class ControlRecordWithControlTypeName
ControlID = controlID;
ControlName = controlName;
ControlTypeID = controlTypeID;
ControlTypeName = controlTypeName;
public short ControlTypeID { get; set; }
AllowEdit = AllowNew = AllowRemove = RaiseListChangedEvents = true;
public class ControlCacheTemp : BindingList<ControlRecordWithControlTypeName>, IDisposable
Dispose(true);
Hi TJ,
Thanks for providing the code. We've been able to create a sample out of it and debug it. The reason you are not able to select the added records is because in the sample, in dgControls_InitializeTemplateAddRecord, you are setting their Enabled to false. This will make the record non-editable as well as non-selectable.
Hope this helps,
Sandip