Esempio n. 1
0
        /// <summary>
        /// Sets grid paras (column) Draw graph according passed configuration
        /// </summary>
        /// <param name="configuration">Graph configuration</param>
        /// <param name="ownerSize">Owner size.</param>
        /// <param name="context">Configuration context.</param>
        public void SetConfiguration(TableConfiguration configuration, Size ownerSize, object context)
        {
            var dataSource = new DataTable();

            dataGridView.AutoGenerateColumns = false;

            _plainData = configuration.TableSource.GetPlainData(context);
            dataGridView.ColumnCount = configuration.ColumnDefinitions.Count;

            if (configuration.UseAutoSize)
            {
                dataGridView.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.Fill;
            }
            else
            {
                dataGridView.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.ColumnHeader;
            }
            dataGridView.AutoSizeRowsMode = DataGridViewAutoSizeRowsMode.AllCells;

            for (int i = 0; i < configuration.ColumnDefinitions.Count; i++)
            {
                var column = dataGridView.Columns[i];
                var definition = configuration.ColumnDefinitions[i];

                column.Tag = definition;
                column.DefaultCellStyle.Format = definition.Format;
                column.HeaderText = definition.ColumnName;
                column.DataPropertyName = definition.ColumnName;

                column.DefaultCellStyle.Alignment = definition.Align.GetColumnAlign();
                column.DefaultCellStyle.Font = new Font(string.Empty, Convert.ToInt32(definition.FontSize ?? "8"), definition.GetFontStyle());

                column.HeaderCell.Style.Alignment = definition.HeaderAlign.GetColumnAlign();
                column.HeaderCell.Style.Font = new Font(
                    string.Empty,
                    Convert.ToInt32(definition.HeaderFontSize ?? "8"),
                    definition.GetHeaderFontStyle());

                var columnConfig = _stateSettings.GetColumnSettings(definition.Tag);
                if (!configuration.UseAutoSize)
                {
                    column.Width = columnConfig.Width;
                }

                column.Visible = columnConfig.Visible;

                dataSource.Columns.Add(definition.ColumnName, definition.Type.GetClrType());
            }

            foreach (var rows in _plainData)
            {
                dataSource.LoadDataRow(rows.Values.ToArray(), true);
            }

            dataGridView.DataSource = dataSource.DefaultView;
        }
        /// <summary>
        /// Sets grid paras (column) Draw graph according passed configuration
        /// </summary>
        /// <param name="configuration">Graph configuration</param>
        /// <param name="ownerSize">Owner size.</param>
        /// <param name="context">Configuration context.</param>
        public void SetConfiguration(TableConfiguration configuration, Size ownerSize, object context)
        {
            var dataSource = new DataTable();

            dataGridView.AutoGenerateColumns = false;

            _plainData = configuration.TableSource.GetPlainData(context);
            dataGridView.ColumnCount = configuration.ColumnDefinitions.Count;

            if (configuration.UseAutoSize)
            {
                dataGridView.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.Fill;
            }
            else
            {
                dataGridView.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.ColumnHeader;
            }
            dataGridView.AutoSizeRowsMode = DataGridViewAutoSizeRowsMode.AllCells;

            for (int i = 0; i < configuration.ColumnDefinitions.Count; i++)
            {
                var column     = dataGridView.Columns[i];
                var definition = configuration.ColumnDefinitions[i];

                column.Tag = definition;
                column.DefaultCellStyle.Format = definition.Format;
                column.HeaderText       = definition.ColumnName;
                column.DataPropertyName = definition.ColumnName;

                column.DefaultCellStyle.Alignment = definition.Align.GetColumnAlign();
                column.DefaultCellStyle.Font      = new Font(string.Empty, Convert.ToInt32(definition.FontSize ?? "8"), definition.GetFontStyle());

                column.HeaderCell.Style.Alignment = definition.HeaderAlign.GetColumnAlign();
                column.HeaderCell.Style.Font      = new Font(
                    string.Empty,
                    Convert.ToInt32(definition.HeaderFontSize ?? "8"),
                    definition.GetHeaderFontStyle());

                var columnConfig = _stateSettings.GetColumnSettings(definition.Tag);
                if (!configuration.UseAutoSize)
                {
                    column.Width = columnConfig.Width;
                }

                column.Visible = columnConfig.Visible;

                dataSource.Columns.Add(definition.ColumnName, definition.Type.GetClrType());
            }

            foreach (var rows in _plainData)
            {
                dataSource.LoadDataRow(rows.Values.ToArray(), true);
            }

            dataGridView.DataSource = dataSource.DefaultView;
        }
 /// <summary>
 /// Load configuration from XML in stream and draw graph
 /// </summary>
 /// <param name="stream">Xml configuration stream</param>
 /// <param name="ownerSize">Owner size.</param>
 /// <param name="context">Configuration context.</param>
 public void SetConfiguration(Stream stream, Size ownerSize, object context)
 {
     SetConfiguration(TableConfiguration.LoadFromXml(stream), ownerSize, context);
 }
 /// <summary>
 /// Load configuration from XML file and draw graph
 /// </summary>
 /// <param name="fileName">XML configuration filename</param>
 /// <param name="ownerSize">Owner size.</param>
 /// <param name="context">Configuration context.</param>
 public void SetConfiguration(string fileName, Size ownerSize, object context)
 {
     SetConfiguration(TableConfiguration.LoadFromXml(fileName), ownerSize, context);
 }