1

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. Commented Feb 26, 2012 at 23:45

1 Answer 1

1

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

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.