I have an ObservableCollection:
public ObservableCollection<FieldsDataGrid> ocEingaben = new ObservableCollection<FieldsDataGrid>();
And my Fields:
public class FieldsDataGrid
{
public string Teil;
public decimal Preis;
}
now I binded it to my DataGrid like this:
<DataGrid Style="{DynamicResource DataGridStyle}"
Margin="10" SelectionUnit="CellOrRowHeader" AutoGenerateColumns="False"
CanUserAddRows="True" CanUserDeleteRows="True" SelectionMode="Single"
x:Name="IDGrid" ItemsSource="{Binding ocEingaben}"
GridLinesVisibility="None" ScrollViewer.CanContentScroll="True"
ScrollViewer.VerticalScrollBarVisibility="Auto" MaxHeight="380"
ScrollViewer.HorizontalScrollBarVisibility="Auto">
<DataGrid.Columns >
<DataGridTextColumn Header="Teil" Binding="{Binding Titel}" Width="*"/>
<DataGridTextColumn Header="Preis" Binding="{Binding Preis}" Width="*"/>
</DataGrid.Columns>
</DataGrid>
I want it like that, that I type Excel Columns in an TextBox and the "Teil" Column will update with data from the Excel, but that Is not relevant for this Question.
Because when Im testing only the function of adding input after the Text Input it not really work.
Keydown event of my TextBox Input:
if (e.Key == Key.Return)
{
View.editotherList();
IDGrid.ItemsSource = View.ocEingaben;
InputCell.Clear();
}
ocEingaben is my Collection and in that Method I add data to the Collection with this test data:
ocEingaben.Add(new FieldsDataGrid() { Teil = "Zellenwert", Preis = 0.0m });
but after I made the Input I get the number of the rows but the Values are not displaying:
Anyone an Idea?