Is it possible to set the text of a Textbox in code behind of a unbounded TemplateField ?
Hello Stephane,
Thank you for contacting Infragistics. Yes you can but walk me through your requirements in detail. There are a couple ways to identify the cell you can hook events if the end user clicks grid. You can use RecordActivated or CellChanged event to identify the cell and then change the value.
You can also iterate the grid's records collection, fields collection etc to get the cell.
To be more specific, i'm trying to apply a red border to the textbox that is into a TemplateField when he is empty :
<igDP:TemplateField Name="SheetsSpans" AllowEdit="False" Width="185" Label="{x:Static resx:Labels.VerifFormDeckMultiple_SheetsGridSpans}" BindingType="Unbound" ToolTip="{x:Static resx:Tooltips.VerifFormDeckMultiple_SheetsGridSpans}"> <igDP:TemplateField.DisplayTemplate> <ItemContainerTemplate> <TextBox x:Name="txtSheetsSpans" IsReadOnly="True" Margin="1,1,1,1" Background="Transparent" BorderBrush="Transparent"> </TextBox> </ItemContainerTemplate> </igDP:TemplateField.DisplayTemplate> </igDP:TemplateField>
in code behind :
private void GrdSheets_InitializeRecord(object sender, InitializeRecordEventArgs e) { if (e.Record is DataRecord dr) { if (dr != null) {
Cell cell = dr.Cells["SheetsSpans"];
??????????? (how can i access textbox ???)
Hello,
I believe there is a better and more efficient way to achieve with our DataErrorInfo interface. We have a topic explaining how to invalidate data and even contains a red border as you described.
https://www.infragistics.com/help/wpf/xamdatapresenter-styling-data-errors
And if i want to set text into textbox, how can i achieve this ? Remember that is an unbound TemplateField with a Textbox in it. Thanks.
I don't see any binding on the your Textbox for the TemplateField so you would just have to add that. <TextBlock Text="{Binding Path=(igEditors:TemplateEditor.Editor).Value, RelativeSource={RelativeSource Self}}"Use the TemplateEditorValueBinding markup extension to facilitate the binding to the underlying data.
TemplateEditorValueBinding
igEditors:TemplateEditor.Editor don't exist (Editor) and the textbox is readonly just for display a calculated information, i'm not in edition... in our case the xamDataGrid is used to display only our data. We have a column with a button to edit the current row in a new independant window (complex need). So all Template fields have a textbox binded to data, except 2 Template Fields with textbox that are calculated and i need to feed this textbox with a calculated data in code behind. Does it simply possible ? a textbox in a TemplateField cannot be accessed anywhere ?
Is there a specific reason you are using a TemplateField and not an Unbound field? The following topic demonstrates how to wire up Fields with BindingType set as Unbound to present calculated data
https://www.infragistics.com/help/wpf/xamcalculationmanager-using-xamcalculationmanager-with-xamdatagrid
Let me know if this is more inline with what you are trying to achieve.
With a unbounded TextField i can display my calculated value, but we want to keep a similar appearance between all the columns and allow the copy / paste of text, that's why we try to use the TextBox in a TemplateField (unbound). In addition we would like to put the red border when the text is empty ...
For styling the XamDataGrid please refer to our online documentation and styling points. For marking an empty text with a red border you can do something like this with a trigger.
eg.
<Style TargetType="{x:Type ig:DataRecordCellArea}"> <Style.Triggers> <DataTrigger Value=""> <Setter Property="BorderBrush" Value="Red"/> <Setter Property="BorderHoverBrush" Value="Red"/> <Setter Property="BorderActiveBrush" Value="Red"/> <Setter Property="BorderSelectedBrush" Value="Red"/> <Setter Property="BorderThickness" Value="2"/> </DataTrigger> </Style.Triggers></Style>