In WPF i've added a DataGrid:
<DataGrid x:Name="dataGridProdotti" HorizontalAlignment="Left" Margin="10,56,0,0" VerticalAlignment="Top" Height="250" Width="426" SelectionChanged="dataGridProdotti_SelectionChanged" IsReadOnly="False"/>
with the property
IsReadOnly="False"
Then i do:
dataGridProdotti.ItemsSource = myList
Why if i double click on a cell, that cell doesn't go in the edit mode?
You need to add DataColumns in the DataGrid
<DataGrid x:Name="dataGridProdotti"
HorizontalAlignment="Left"
ItemsSource="{Binding Values}"
Margin="10,10,0,192" Width="481" AutoGenerateColumns="False">
<DataGrid.Columns>
<DataGridTextColumn IsReadOnly="False" Binding="{Binding Path=Name}" Header="List" />
</DataGrid.Columns>
</DataGrid>
And also Dont bind the list<string>
directly to datasource of the DataGrid, Create one custom class and then bind like below.
private List<Country> value = new List<Country>();
public MainWindow()
{
InitializeComponent();
this.Values.Add(new Country{ Name = "America"});
this.Values.Add(new Country{Name = "Africa"});
this.Values.Add(new Country{Name = "India"});
}
public List<Country> Values
{
get
{
return this.value;
}
set
{
this.value = value;
}
}
}
public class Country
{
public string Name { get; set; }
}
Now the DataGrid is editable.
I dont see you having any columns in your datagrid,
Just drop a DataGrid control to your view and bind the ItemsSource to a collection of data objects and you're done. The DataGrid provides a feature called AutoGenerateColumns that automatically generates column according to the public properties of your data objects
Alternatively you can define your columns manually by setting the AutoGenerateColumns property to False. In this case you have to define the columns in the Columns collection of the data grid.
If you want to edit your datagrid cell, you should define a datatemplateColumn,
<sdk:DataGridTemplateColumn Header="Yourheadername" Width="150" CanUserResize="False" CanUserReorder="False">
<sdk:DataGridTemplateColumn.CellTemplate>
<DataTemplate>
<TextBlock Margin="2" VerticalAlignment="Center" x:Name="txtblock" Text="{Binding Test,Mode=TwoWay}" />
</DataTemplate>
</sdk:DataGridTemplateColumn.CellTemplate>
</sdk:DataGridTemplateColumn>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With