After a LINQ query, I try to connect the response with the DataGrid:

context = new cokoEntities4(); s = new List<string>(); var itemList = from SchoolName in context.View_1 select SchoolName; foreach (var item in itemList) { Console.WriteLine(item.SchoolName); s.Add(item.SchoolName); } dg.ItemsSource = s; 

Here is what he shows me:

alt text

Although it is correct to output to the console:

 ГБОУ «Гимназия № 12» ГБОУ «Гимназия № 14» ГБОУ «Общеобразовательная школа-интернат № 1» ГБОУ «Общеобразовательная школа-интернат для детей-сирот и детей, оставшихся без попечения родителей № 2» ГБОУ «Президентский лицей» 

Why it happens?

    1 answer 1

    DataGrid is filled with properties in objects, the String type has one property, it is Lenght, which is issued. Use objects with explicit properties to prevent this from happening, for example:

     class Institution{ public String Title { get; set; } }; List<Institution> list = new List<Institution>(); /******* ********/ var itemList = from SchoolName in context.View_1 select new Institution(){Title = SchoolName}; foreach (var item in itemList) { list.Add(item); } dg.ItemsSource = list; 
    • The compiler generates an error around: @Alex Krass. To format the code, select it with the mouse and press the {} button of the editor. 'select new Institution () {Title = SchoolName.ToString ()};' - Adam
    • one
      @derkode, if you are talking about an error, then cite its text immediately. - Alex Krass