Błąd przy tworzeniu DataGridView

0

Co jakiś czas pojawia mi się błąd: "This operation cannot be performed while an auto-filled column is being resized" podczas wykonywania metody form.Show(); Wygląda na to, że problem dotyczy DataGridView.
Spotkaliście się może z czymś takim?

Pozdrawiam,
Zoritt

0

Witam

Prześlij kod źródłowy.

0

Wywołanie:

 
foreach (Form form in MdiChildren)
            {
                if (form.Name == "SlownikiJednostki")
                {
                    form.Activate();
                    return;
                }
            }

            Slowniki.SlownikiJednostki child = new Slowniki.SlownikiJednostki();
            child.Name = "SlownikiJednostki";
            child.MdiParent = this;
            try
            {
                child.Show();
            }
            catch (InvalidOperationException)
            {
                child.Show();
            }

To podwoje wywołanie Show() to porada z http://dotnet.itags.org/web-forms/75052/ ale coś mnie nie przekonuje :-)

 
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace BrING.Slowniki
{
    public partial class SlownikiJednostki : Pomocne.SlownikStandard
    {
        public SlownikiJednostki()
        {
            InitializeComponent();
            this.Text = "Jednostki";
            this.zapytanie.sqlCommandText = "SELECT * FROM DBA.Jednostki";
            this.dataTable=this.zapytanie.wykonajSelect2DataTable();
            this.nazwaId = "idJednostki";
            bindingSource.DataSource = dataTable;
            dataGridViewStandard1.DataSource = bindingSource;
        }

        public override void dodajButton_Click(object sender, EventArgs e)
        {
            EdycjaJednostki child = new EdycjaJednostki();
            child.idItem = 0;
            child.Owner = this;
            child.ShowDialog();
            if (child.idItem!=0)
                refreshDataGrid(child.idItem);
            base.dodajButton_Click(sender, e);
        }
        public override void poprawButton_Click(object sender, EventArgs e)
        {
            EdycjaJednostki child = new EdycjaJednostki();
            child.idItem = (int)dataGridViewStandard1.CurrentRow.Cells[0].Value;
            child.Owner = this;
            child.ShowDialog();
            if (child.idItem != 0)
                refreshDataGrid(child.idItem);

            base.poprawButton_Click(sender, e);
        }

        public override void usunButton_Click(object sender, EventArgs e)
        {
            base.usunButton_Click(sender, e);
        }

        private void SlownikiJednostki_Load(object sender, EventArgs e)
        {
            
        }
    }
}
 
namespace BrING.Slowniki
{
    partial class SlownikiJednostki
    {
        /// <summary>
        /// Required designer variable.
        /// </summary>
        private System.ComponentModel.IContainer components = null;

        /// <summary>
        /// Clean up any resources being used.
        /// </summary>
        /// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
        protected override void Dispose(bool disposing)
        {
            if (disposing && (components != null))
            {
                components.Dispose();
            }
            base.Dispose(disposing);
        }

        #region Windows Form Designer generated code

        /// <summary>
        /// Required method for Designer support - do not modify
        /// the contents of this method with the code editor.
        /// </summary>
        private void InitializeComponent()
        {
            this.dataGridViewStandard1 = new BrING.Pomocne.DataGridViewStandard();
            this.idJednostki = new System.Windows.Forms.DataGridViewTextBoxColumn();
            this.Aktywny = new System.Windows.Forms.DataGridViewCheckBoxColumn();
            this.Symbol = new System.Windows.Forms.DataGridViewTextBoxColumn();
            this.Nazwa = new System.Windows.Forms.DataGridViewTextBoxColumn();
            ((System.ComponentModel.ISupportInitialize)(this.splitContainer1)).BeginInit();
            this.splitContainer1.Panel1.SuspendLayout();
            this.splitContainer1.SuspendLayout();
            ((System.ComponentModel.ISupportInitialize)(this.dataTable)).BeginInit();
            ((System.ComponentModel.ISupportInitialize)(this.bindingSource)).BeginInit();
            ((System.ComponentModel.ISupportInitialize)(this.dataGridViewStandard1)).BeginInit();
            this.SuspendLayout();
            // 
            // splitContainer1
            // 
            // 
            // splitContainer1.Panel1
            // 
            this.splitContainer1.Panel1.Controls.Add(this.dataGridViewStandard1);
            this.splitContainer1.Size = new System.Drawing.Size(617, 516);
            this.splitContainer1.SplitterDistance = 422;
            // 
            // dataGridViewStandard1
            // 
            this.dataGridViewStandard1.AllowUserToAddRows = false;
            this.dataGridViewStandard1.AllowUserToDeleteRows = false;
            this.dataGridViewStandard1.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize;
            this.dataGridViewStandard1.Columns.AddRange(new System.Windows.Forms.DataGridViewColumn[] {
            this.idJednostki,
            this.Aktywny,
            this.Symbol,
            this.Nazwa});
            this.dataGridViewStandard1.Dock = System.Windows.Forms.DockStyle.Fill;
            this.dataGridViewStandard1.Location = new System.Drawing.Point(0, 0);
            this.dataGridViewStandard1.Name = "dataGridViewStandard1";
            this.dataGridViewStandard1.ReadOnly = true;
            this.dataGridViewStandard1.Size = new System.Drawing.Size(617, 422);
            this.dataGridViewStandard1.TabIndex = 0;
            // 
            // idJednostki
            // 
            this.idJednostki.DataPropertyName = "idJednostki";
            this.idJednostki.HeaderText = "idJednostki";
            this.idJednostki.Name = "idJednostki";
            this.idJednostki.ReadOnly = true;
            this.idJednostki.Visible = false;
            // 
            // Aktywny
            // 
            this.Aktywny.DataPropertyName = "Aktywny";
            this.Aktywny.FalseValue = "0";
            this.Aktywny.HeaderText = "A";
            this.Aktywny.Name = "Aktywny";
            this.Aktywny.ReadOnly = true;
            this.Aktywny.Resizable = System.Windows.Forms.DataGridViewTriState.True;
            this.Aktywny.SortMode = System.Windows.Forms.DataGridViewColumnSortMode.Automatic;
            this.Aktywny.TrueValue = "1";
            this.Aktywny.Width = 25;
            // 
            // Symbol
            // 
            this.Symbol.DataPropertyName = "Symbol";
            this.Symbol.HeaderText = "Symbol";
            this.Symbol.Name = "Symbol";
            this.Symbol.ReadOnly = true;
            this.Symbol.Width = 50;
            // 
            // Nazwa
            // 
            this.Nazwa.AutoSizeMode = System.Windows.Forms.DataGridViewAutoSizeColumnMode.Fill;
            this.Nazwa.DataPropertyName = "Nazwa";
            this.Nazwa.HeaderText = "Nazwa";
            this.Nazwa.Name = "Nazwa";
            this.Nazwa.ReadOnly = true;
            // 
            // SlownikiJednostki
            // 
            this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
            this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
            this.ClientSize = new System.Drawing.Size(617, 516);
            this.Name = "SlownikiJednostki";
            this.Text = "Form1";
            this.Load += new System.EventHandler(this.SlownikiJednostki_Load);
            this.splitContainer1.Panel1.ResumeLayout(false);
            ((System.ComponentModel.ISupportInitialize)(this.splitContainer1)).EndInit();
            this.splitContainer1.ResumeLayout(false);
            ((System.ComponentModel.ISupportInitialize)(this.dataTable)).EndInit();
            ((System.ComponentModel.ISupportInitialize)(this.bindingSource)).EndInit();
            ((System.ComponentModel.ISupportInitialize)(this.dataGridViewStandard1)).EndInit();
            this.ResumeLayout(false);

        }

        #endregion

        private Pomocne.DataGridViewStandard dataGridViewStandard1;
        private System.Windows.Forms.DataGridViewTextBoxColumn idJednostki;
        private System.Windows.Forms.DataGridViewCheckBoxColumn Aktywny;
        private System.Windows.Forms.DataGridViewTextBoxColumn Symbol;
        private System.Windows.Forms.DataGridViewTextBoxColumn Nazwa;

    }
}

0

Główny problem jest taki, że błąd wyskakuje raz na kilka uruchomień.
Teraz zmieniałem tak, że w designerze dałem none zamiast fill natomiast:

 
this.Nazwa.AutoSizeMode = System.Windows.Forms.DataGridViewAutoSizeColumnMode.Fill;

wstawiłem do onLoad. Może to coś pomoże.

Pozdrawiam,
Zoritt

1 użytkowników online, w tym zalogowanych: 0, gości: 1