-1

So I'm currently creating a C# WPF application with a DataGrid to show the user some strings he entered before. I'm pretty new to WPF and programming in general so I have no clue where to begin. My problem is that I don't know how to fill data in the DataGrid. This could be a duplicate but as there aren't simple tutorials for beginners I would be happy about some help.

I currently have an ArrayList userInput filled with strings:

userInput{"the", "brown", "fox", "jumps", "over", "the", "lazy", "dog"}

This is the result I want to achieve:

(1) the   | brown
(2) fox   | jumps
(3) over  | the
(4) lazy  | dog

I did some research and I found something named data-binding but I don't really understand how it works. Thank you for your help in advance.

Noël Kra
  • 40
  • 9
  • https://stackoverflow.com/questions/22922533/how-do-i-automagically-bind-a-string-array-to-a-wpf-datagrid – go.. Oct 03 '18 at 08:09
  • Create a model, fill a list of model with data, bind this list to datagrid – Antoine V Oct 03 '18 at 08:09
  • @snnbrn I found that post already but I don't understand how it works. I'm really a beginner thats the main problem why I asked that question... – Noël Kra Oct 03 '18 at 08:14
  • Read this first: [Data Binding Overview](https://learn.microsoft.com/en-us/dotnet/framework/wpf/data/data-binding-overview). – Clemens Oct 03 '18 at 08:16

1 Answers1

0

I can suggest the solution for you in a simpler way. you must have schema first. simply need to convert your array list to an CustomClass list

    public class User
    {
        public string Name { get; set; }
    }




  public List<User> users = new List<User>();

  users.Add(new User() { Name = "dogs" });
  users.Add(new User() { Name = "dog" });
  users.Add(new User() { Name = "cat" });
  users.Add(new User() { Name = "cats" });


 this.dataGrid1.ItemsSource = users;

  <DataGrid Height="179" HorizontalAlignment="Left" Margin="54,65,0,0" Name="dataGrid1" VerticalAlignment="Top" Width="382">
        </DataGrid>
go..
  • 958
  • 7
  • 15