DataTable _fcDTable = new DataTable("DataTable: Frequency Converter"); // Инициализация столбцов таблицы _fcDTable.Columns.Add(_timeColumnName); _fcDTable.Columns[_timeColumnName].DataType = typeof(DateTime); foreach (string name in FCParametersStructure.getParametersNames()) { _fcDTable.Columns.Add(name); _fcDTable.Columns[name].DataType = typeof(int); } 

When trying to bind data to a DataGrid table as follows:

  TableWindow(DataTable dTable) { InitializeComponent(); this.dGrid.ItemsSource = dTable.DefaultView; this.Show(); } 

... and even making sure that the data is still loaded: Reference values

... I find that most of the data for some reason is not displayed at all: Window display

  1. What is the reason for such a table drawing?
  2. Should I use DataTable in a situation where I have to work with hundreds of thousands of records? (scrolling performance leaves much to be desired)
  3. Which class is better to use to initialize a non-one type data table?
  • it seems that AutoGenerateColumns = "False" is not set, although the column names are delusional - vitidev
  • Yes, it is not really set, because the columns in no other way in this example are created and they are loaded with the correct headers with the correct number. The question is why only some of them could be loaded, although the type for everyone except the first 'DateTime' is the same ('int'). - Artyom Ionash
  • It's not entirely clear which fields are mapped, write how you add data and what is at the output of dTable.DefaultView. - Alexsandr Ter
  • As far as I remember, when ItemsSource is used reflection and stupidly takes the name of the field. Is your string a class or just an array of objects? - Alexsandr Ter
  • @Alexsandr Ter: the row here is the initialized DataRow row = _dTable.NewRow(); , obtained from the DataTable _dTable with columns initialized from some list string[] . - Artyom Ionash

1 answer 1

Initializing the entire DataGrid through assigning a DataTable object in its ItemsSource property is sensitive to the presence of punctuation marks in the column names (in this case, ',' , '.' , '/' ) And does not display the column fields in which they are present in the headers .

PS Line-by-line initialization, as far as I understand, is impossible, otherwise, by adding an object to the collection of DataGrid.Items , the number of properties of which is equal to the number of columns of the table?