I am new to C# wpf and uses an ObservableCollection to populate the columns and rows of a DataGrid. The user must be able to interact with the data in the cells with the exception of two specific columns, which should contain read-only/static content (e.g. a unique row ID).
Is there a way to make specific columns read-only in an ObservableCollection? Or should such data be in a separate DataGrid populated by a ReadOnlyObservableCollection (which in my opinion seems overcomplicated)?
In my *.xaml file I have the DataGrid as:
<DataGrid Name="OptionsGrid" ItemsSource="{Binding Options}">
</DataGrid>
And the corresponding code is:
public ObservableCollection<OptionsData> Options { get; init; }
Options = new ObservableCollection<OptionsData>
{
new OptionsData() {Id = "123", IsActive = true, OptionCheck = true, OptionName = "Name"},
new OptionsData() {Id = "456", IsActive = false, OptionCheck = false, OptionName = "Name2"},
};
DataContext = this;
//
public class OptionsData
{
public string Id { get; set; }
public bool IsActive { get; set; }
public bool OptionCheck { get; set; }
public string OptionName { get; set; }
}
Edit: Added code example