Reputation: 121
[Update: I have solved this problem by making each column of the grid IsReadOnly = false]
I want to make my control:datagrid editable. That is - In UI I want to edit the values in a cell. I have tried This. It can't make my cell editable. What is in my code:
<controls:DataGrid x:Name="grid"
Grid.Row="1"
Margin="40, 40, 40, 40"
Height="Auto"
Width="Auto"
AutoGenerateColumns="False"
BorderBrush="LightGray"
BorderThickness="1"
GridLinesVisibility="All"
AlternatingRowBackground="LightBlue"
HeadersVisibility="Column"
CanUserSortColumns="True"
Sorting="DataGrid_Sorting"
FrozenColumnCount="2"
ColumnWidth="150"
ItemsSource="{Binding collection, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}"
IsReadOnly="False">
</Style>
</controls:DataGrid.RowStyle> -->
</controls:DataGrid>
And, In xaml.cs:
public static ObservableCollection<object> collection { get; set; }
public static DataTable dataTable, tempTable;
grid.Columns.Clear();
for (int i = 0; i < dataTable.Columns.Count; i++)
{
grid.Columns.Add(new DataGridTextColumn()
{
Header = dataTable.Columns[i].ColumnName,
Binding = new Binding { Path = new PropertyPath("[" + i.ToString() + "]") }
});
}
collection = new ObservableCollection<object>();
foreach (DataRow row in dataTable.Rows)
{
collection.Add(row.ItemArray);
}
grid.ItemsSource = collection;
My target is to make something like this in the figure
Upvotes: 2
Views: 575
Reputation: 121
I have solved this problem by making each column of the grid IsReadOnly = false. For example: grid.Columns[1].IsReadOnly = false;
Upvotes: 2