/// <summary> /// Loads the table data. /// </summary> private void LoadTableData() { if (!project.ConfigBase.Load(out string errMsg)) { appData.ProcError(errMsg); } // reset the binding source bindingSource.DataSource = null; // create a data table dataTable = tableFilter == null? baseTable.ToDataTable() : baseTable.SelectItems(tableFilter).ToDataTable(baseTable.ItemType); dataTable.DefaultView.Sort = baseTable.PrimaryKey; maxRowID = dataTable.DefaultView.Count > 0 ? (int)dataTable.DefaultView[dataTable.DefaultView.Count - 1][baseTable.PrimaryKey] : 0; // set the binding source before creating grid columns in case of work on Mono if (ScadaUtils.IsRunningOnMono) { bindingSource.DataSource = dataTable; } // bind table events dataTable.TableNewRow += dataTable_TableNewRow; dataTable.RowChanged += dataTable_RowChanged; dataTable.RowDeleted += dataTable_RowDeleted; // create grid columns ColumnBuilder columnBuilder = new ColumnBuilder(project.ConfigBase); dataGridView.Columns.Clear(); dataGridView.Columns.AddRange(columnBuilder.CreateColumns(baseTable.ItemType)); // set default values foreach (DataGridViewColumn column in dataGridView.Columns) { if (column.Tag is ColumnOptions options && options.DefaultValue != null) { dataTable.Columns[column.Name].DefaultValue = options.DefaultValue; } } if (tableFilter != null) { dataTable.Columns[tableFilter.ColumnName].DefaultValue = tableFilter.Value; } // set the binding source if (!ScadaUtils.IsRunningOnMono) { bindingSource.DataSource = dataTable; } dataGridView.AutoSizeColumns(); ChildFormTag.Modified = baseTable.Modified; }
/// <inheritdoc /> /// <summary> /// Loads the table data. /// </summary> protected override void LoadTableData() { base.LoadTableData(); if (!project.ConfigBase.Load(out string errMsg)) { appData.ProcError(errMsg); } dataTable = baseTable.ToDataTable(); dataTable.RowChanged += dataTable_RowChanged; dataTable.RowDeleted += dataTable_RowDeleted; bindingSource.DataSource = dataTable; ColumnBuilder columnBuilder = new ColumnBuilder(project.ConfigBase); dataGridView.Columns.AddRange(columnBuilder.CreateColumns(baseTable.ItemType)); dataGridView.AutoResizeColumns(); ChildFormTag.Modified = baseTable.Modified; }