I would like to enable or disable a TextBox depending on the ComboBox value. I tried following code, but couldn't find textblock control. Can someone please help?C# code: editor.SelectionChanged += new SelectionChangedEventHandler(ConditonCombo_SelectionChanged); - - - void ConditonCombo_SelectionChanged(object sender, SelectionChangedEventArgs e) { ComboBox editor = (ComboBox)sender; if (editor != null) { // find textbox _tblValue2 and enable or disable depending on combo-box value. } } Xaml Code: <igGrid:XamWebGrid x:Name="_dgAlertConditionsList" HeaderVisibility="Collapsed" AutoGenerateColumns="False" ColumnWidth="*" Height="300" Width="650" ItemsSource="{Binding AlertConditionList}" Margin="0,20,0,0"> <igGrid:XamWebGrid.SelectionSettings> <igGrid:SelectionSettings CellClickAction="SelectRow" RowSelection="Single"></igGrid:SelectionSettings> </igGrid:XamWebGrid.SelectionSettings> <igGrid:XamWebGrid.EditingSettings> <igGrid:EditingSettings AllowEditing="Row" IsMouseActionEditingEnabled="SingleClick"/> </igGrid:XamWebGrid.EditingSettings> <igGrid:XamWebGrid.Columns> <igGrid:TemplateColumn Key="CondOperator" Width="120" HorizontalContentAlignment="Stretch"> <igGrid:TemplateColumn.ItemTemplate> <DataTemplate> <TextBlock x:Name="CondOperatorDisplay" Text="{Binding CondOperator.Label}" Margin="3,2,3,2"/> </DataTemplate> </igGrid:TemplateColumn.ItemTemplate> <igGrid:TemplateColumn.EditorTemplate> <DataTemplate> <ComboBox x:Name="CondOperatorList" SelectedItem="{Binding CondOperator,Mode=TwoWay}" DisplayMemberPath="Label" Margin="3,2,3,2"/> </DataTemplate> </igGrid:TemplateColumn.EditorTemplate> </igGrid:TemplateColumn> - - - - - - - <igGrid:TemplateColumn Key="Value2" Width="*" HorizontalContentAlignment="Stretch"> <igGrid:TemplateColumn.ItemTemplate> <DataTemplate> <TextBlock x:Name="_tblValue2" Text="{Binding Value2}" Margin="3,2,3,2"/> </DataTemplate> </igGrid:TemplateColumn.ItemTemplate> <igGrid:TemplateColumn.EditorTemplate> <DataTemplate> <TextBox x:Name="_tbValue2" IsEnabled="False" Text="{Binding Value2,Mode=TwoWay}" Margin="3,2,3,2"/> </DataTemplate> </igGrid:TemplateColumn.EditorTemplate> </igGrid:TemplateColumn> </igGrid:XamWebGrid.Columns> </igGrid:XamWebGrid>
I think it would be easier to handle this in the datasource. Add an IsValue2Editable property (or whatever you wanna call it) to your datasource and bind it to the IsEnabled property of the textbox. Then in the setter for whatever property the combobox is bound to just update the IsValue2Editable and fire a PropertyChangedEvent for it.
Thanks for the quick answer, I this this is really good idea, I tried it, it does work except one issue. When value is selected from combo-box, Value2 field is not enabled, but if I click on different row and refocus to the same row, it does work. Is there any trick here?
Xaml:
C# code:
==========
void ConditonCombo_SelectionChanged(object sender, SelectionChangedEventArgs e)
{
ComboBox editor = (ComboBox)sender;
if (editor != null)
Token tok = (Token)editor.SelectedItem;
if (tok != null)
if (this._DefineAlertsView._dgAlertConditionsList.SelectionSettings.SelectedRows[0].Data.GetType().FullName.Equals("AlertsUI.Model.AlertCondition"))
AlertCondition alrtconddata = (AlertCondition)this._DefineAlertsView._dgAlertConditionsList.SelectionSettings.SelectedRows[0].Data;
if (alrtconddata != null)
{ alrtconddata.isEnabledValue2 = (tok.Key.Equals(
"RANGE")); }
}
Hi,
TwoWay bindings work via the INotifyPropertyChanged interface.
So make sure you implement that interface on your DataObject, then raise the PropertyChanged event, in the Setter of the IsEnabledValue2 property, and be sure to pass th EXACT property name into the event args.
-SteveZ
works Perfect.. Many many thanks for prompt reply.