Friday, April 20, 2012

WPF Datagrid edit only single cell value

I have a WPF Datagrid with 2 columns say parametername and value.



My Requirement is only one value(cell content) for a Particular parametername should be editable and the entire Datagrid contents should be read only....



And I have a save button to save the values.



I had been researching from couple of days for an appropriate solution which observes to be a common requirement in many cases but I havent found...



Please any solution or ideas will be appreciated..



Here is XAML & cs : When the Datagrid loads I want only the PM2 cell value to be in edit mode and all other datagrid content should be greyed out or non-editable..






<Grid>
<DataGrid ItemsSource="{Binding}" AutoGenerateColumns="False"
Margin="20,57,18,19" Name="dataGrid1"
Height="250" SelectionUnit="Cell" >

<DataGrid.Columns>
<DataGridTextColumn Binding="{Binding ParameterName}" Width="100" Header="Parameter Name" IsReadOnly="True"/>

<DataGridTextColumn Binding="{Binding Value}" Width="100" Header="Value" />

</DataGrid.Columns>

</DataGrid>
</Grid>





And my CS code



public partial class dgSF : Window
{

ObservableCollection<ParameterSet> pmset;

public dgSF()
{
InitializeComponent();
pmset = new ObservableCollection<ParameterSet>();

pmset.Add(new ParameterSet() { ParameterName = "PM1", Value = 10 });

pmset.Add(new ParameterSet() { ParameterName = "PM2", Value = 50 });

pmset.Add(new ParameterSet() { ParameterName = "PM3", Value = 70 });

pmset.Add(new ParameterSet() { ParameterName = "PM4", Value = 80 });

pmset.Add(new ParameterSet() { ParameterName = "PM5", Value = 100 });

dataGrid1.ItemsSource = pmset;
}
}

public class ParameterSet
{

public string ParameterName { get; set; }

public int Value { get; set; }

}


Thanks So much,



Anu





No comments:

Post a Comment