I import from a text file with delimiters lines, the values ​​of which are then converted to double.

var List<double[]> inData = new List<double[]>(); var line = reader.ReadLine(); if (line != null) { var elements = line.Split(separator); if (elements.Length!=0) { double[] converted = ToDoubleFromString(elements); //конверчу из строки в дабл if (converted != null) inData.Add(converted); } DataGrid1.ItemsSource = inData; } 

When attempting to specify a DataGrid1.ItemsSource, the values ​​are not displayed in the datagrid, but information about the structure of the array is displayed. How to display the values? I tried to translate it into a double [,] matrix, but the DataGrid does not display it either.

  • Because the elements of the sheet are arrays! In the case of a sheet of this type: List <double> everything will be displayed without additional effort. - wind
  • Well, I have an array of arrays, as it were, and not just values - fundottz
  • How to display it, array of arrays? All in one array or with groupings or something else? - wind
  • in datagrit, by type: Column1 | Column2 | ColumnN inData [0] [0] | inData [0] [1] | inData [0] [2] inData [1] [0] | inData [1] [1] | inData [1] [2] - fundottz

1 answer 1

First, you need not an array of arrays, but an array of class instances. DataGrid alone wonders what your data means! He assumes that his ItemsSource is an IEnumerable <> (in particular, the List <> is appropriate) of instances of some fixed class, and for us it’s better that his assumption be justified. Further, in the class, instead of fields, there should be open properties:

 class DataEntry { public double Speed { get; set; } public double Velocity { get; set; } public double Geschwindigkeit { get; set; } public double Vitesse { get; set; } public double Rapidez { get; set; } } public List<DataEntry> ItemsSource { get; set; } 

So it should already work on the display.

If you also want to catch changes in ItemsSource, you need to go from List <> to ObservableCollection, and implement INotifyPropertyChange in DataEntry .

  • The point is that I don’t know in advance how many values ​​there will be in a string and it’s not possible to bring it to a certain class. - fundottz
  • @fundottz: hmm. and how many columns should be? Should their number change when adding a new item to the list? - VladD
  • the number of elements in a line is not known, it can be different in each line, the elements of a line are double [], each array of values ​​from a line is a List element <double []> inData - fundottz
  • @fundottz: maybe in this case it will help: codeproject.com/Articles/5806/… ? - VladD
  • what you need! Thank! - fundottz