0
votes

I've started using C# WPF very recently, I'm trying to create a DataGrid that collects user inputs and stores it in a List<>, programmatically.
So far this is what I have done.

        private void Introduzir_Click(object sender, RoutedEventArgs e)
        {
        //inValores.Add(new InData(12, 23, 45));

        DataGrid dados = new DataGrid();
        dados.ItemsSource = inValores;
        dados.Width = plotCanvas.ActualWidth;
        dados.Height = plotCanvas.ActualHeight;
        dados.AutoGenerateColumns = false;
        dados.IsReadOnly = false;
        dados.ColumnWidth = 150;
        dados.CanUserAddRows = true;

        DataGridTextColumn ColRaio = new DataGridTextColumn();
        DataGridTextColumn ColMassa = new DataGridTextColumn();
        DataGridTextColumn ColVelocidade = new DataGridTextColumn();
        dados.Columns.Add(ColRaio);
        dados.Columns.Add(ColMassa);
        dados.Columns.Add(ColVelocidade);
        plotCanvas.Children.Add(dados);

        ColRaio.Header = "Raio";
        //ColRaio.Binding = new Binding("[inValores.RAIO]");
        ColMassa.Header = "Massa";
        //ColMassa.Binding = new Binding("[inValores.VELINICIAL]");
        ColVelocidade.Header = "Velocidade";
        //ColVelocidade.Binding = new Binding("[inValores.MASSA]");
        }


Thanks in advance.

1
How to let the user input the values on the grid and save the information to a list. I have seen plenty of tutorials but its just mainly editing data that already exists and most using xaml only.CMCB

1 Answers

1
votes

You can specify binding for each column as twoway.

Binding bRaio=new Binding();
bRaio.Path = new PropertyPath("RAIO");
bRaio.Mode = BindingMode.TwoWay;
ColRaio.Binding = bRaio;

Similarly do for other two columns