Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>you can try some thing like this </p> <pre><code> &lt;Grid&gt; &lt;DataGrid ItemsSource="{Binding A}" AutoGenerateColumns="False" &gt; &lt;DataGrid.Columns&gt; &lt;DataGridTemplateColumn Header="Choose" &gt; &lt;DataGridTemplateColumn.CellTemplate&gt; &lt;DataTemplate&gt; &lt;ComboBox ItemsSource="{Binding ListOfValues}" SelectedValue="{Binding Selected, UpdateSourceTrigger=PropertyChanged}"/&gt; &lt;/DataTemplate&gt; &lt;/DataGridTemplateColumn.CellTemplate&gt; &lt;/DataGridTemplateColumn&gt; &lt;DataGridTemplateColumn Header="Value"&gt; &lt;DataGridTemplateColumn.CellTemplate&gt; &lt;DataTemplate&gt; &lt;TextBox Text="{Binding Selected, UpdateSourceTrigger=PropertyChanged}" IsReadOnly="{Binding ValueAvalible}"/&gt; &lt;/DataTemplate&gt; &lt;/DataGridTemplateColumn.CellTemplate&gt; &lt;/DataGridTemplateColumn&gt; &lt;/DataGrid.Columns&gt; &lt;/DataGrid&gt; &lt;/Grid </code></pre> <p>In the Cell Demplate as of now i have put only TextBox and bound ValueAvalible to readonly Property. You can also have both label and TextBox and you can bind ValueAvalible to visiblity of label and TextBox and. You can hide the text show the label if value is available. If no value is there in the comboBox you can hide label and show the textBox which will give a better user experience like below</p> <pre><code>&lt;StackPanel&gt; &lt;Label Content="{Binding Selected}" Visibility="{Binding ValueAvalible, Converter={StaticResource ResourceKey=booleanToVisiblity}}"/&gt; &lt;TextBox Text="{Binding Selected, UpdateSourceTrigger=PropertyChanged}" Visibility="{Binding ValueAvalible, Converter={StaticResource ResourceKey=invertedBooleanToVisiblity}}"/&gt; &lt;/StackPanel&gt; </code></pre> <p>In your viewModel </p> <pre><code>class ViewModel { public ObservableCollection&lt;Values&gt; A { get; set; } public ViewModel() { A = new ObservableCollection&lt;Values&gt;(); Values vv = new Values(); vv.ListOfValues = new ObservableCollection&lt;string&gt;(); vv.ListOfValues.Add("1"); vv.ListOfValues.Add("2"); vv.Selected = vv.ListOfValues[0]; vv.ValueAvalible = true; A.Add(vv); A.Add(new Values()); } } public class Values : NotifiyPropertyChanged { public ObservableCollection&lt;string&gt; ListOfValues { get; set; } private string selectedValue; public string Selected { get { return selectedValue; } set { selectedValue = value; Notify("Selected"); } } public bool ValueAvalible { get; set; } } public class NotifiyPropertyChanged : INotifyPropertyChanged { public event PropertyChangedEventHandler PropertyChanged; protected void Notify(string propertyName) { if (PropertyChanged != null) { PropertyChanged(this, new PropertyChangedEventArgs(propertyName)); } } } } </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload