Home Forums WinForms controls Xceed Grid for WinForms Keeping columns fixed.

Viewing 3 posts - 1 through 3 (of 3 total)
  • Author
    Posts
  • User (Old forums)
    Member
    Post count: 23064
    #12936 |

    In my Grid 1.1 app I implemented a keep first n columns fixed feature. I used the faq as a starting point. It worked in grid 1.1. After upgrading to grid 2.0 I get an exception: <b><i>An attempt was made to update the PaintManager while it is already updating.</i></b>

    I made a little sample program/form having 1 gridcontrol <b>gridControl1</b> and one checkbox <b>checkBox1</b>. If the checkbox is checked, the first 5 columns are kept fixed.

    Sample code:
    Create a winform project, in the form draw a grid gridControl1 and a checkbox checkBox1.
    Replace the form code by:
    <hr>

    using System;
    using System.Drawing;
    using System.Collections;
    using System.ComponentModel;
    using System.Windows.Forms;
    using System.Data;

    namespace xceedbug
    {
    /// <summary>
    /// Summary description for Form1.
    /// </summary>
    public class Form1 : System.Windows.Forms.Form
    {
    private System.Windows.Forms.CheckBox checkBox1;
    private Xceed.Grid.GridControl gridControl1;
    private Xceed.Grid.GroupByRow groupByRow1;
    private Xceed.Grid.ColumnManagerRow columnManagerRow1;
    private Xceed.Grid.DataRow dataRowTemplate1;

    private string[][] data;
    private int nFixedColumns;
    /// <summary>
    /// Required designer variable.
    /// </summary>
    private System.ComponentModel.Container components = null;

    public Form1()
    {
    //
    // Required for Windows Form Designer support
    //
    InitializeComponent();

    //
    // TODO: Add any constructor code after InitializeComponent call
    //
    }

    /// <summary>
    /// Clean up any resources being used.
    /// </summary>
    protected override void Dispose( bool disposing )
    {
    if( disposing )
    {
    if (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.checkBox1 = new System.Windows.Forms.CheckBox();
    this.gridControl1 = new Xceed.Grid.GridControl();
    this.groupByRow1 = new Xceed.Grid.GroupByRow();
    this.columnManagerRow1 = new Xceed.Grid.ColumnManagerRow();
    this.dataRowTemplate1 = new Xceed.Grid.DataRow();
    ((System.ComponentModel.ISupportInitialize)(this.gridControl1)).BeginInit();
    ((System.ComponentModel.ISupportInitialize)(this.columnManagerRow1)).BeginInit();
    ((System.ComponentModel.ISupportInitialize)(this.dataRowTemplate1)).BeginInit();
    this.SuspendLayout();
    //
    // checkBox1
    //
    this.checkBox1.Location = new System.Drawing.Point(16, 232);
    this.checkBox1.Name = “checkBox1”;
    this.checkBox1.Size = new System.Drawing.Size(136, 24);
    this.checkBox1.TabIndex = 0;
    this.checkBox1.Text = “keep 5 columns fixed”;
    //
    // gridControl1
    //
    this.gridControl1.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left)
    | System.Windows.Forms.AnchorStyles.Right)));
    this.gridControl1.DataRowTemplate = this.dataRowTemplate1;
    this.gridControl1.FixedHeaderRows.Add(this.groupByRow1);
    this.gridControl1.FixedHeaderRows.Add(this.columnManagerRow1);
    this.gridControl1.Location = new System.Drawing.Point(16, 8);
    this.gridControl1.Name = “gridControl1”;
    this.gridControl1.Size = new System.Drawing.Size(568, 224);
    this.gridControl1.TabIndex = 1;
    this.gridControl1.FirstVisibleColumnChanged += new System.EventHandler(this.gridControl1_FirstVisibleColumnChanged);
    //
    // Form1
    //
    this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
    this.ClientSize = new System.Drawing.Size(592, 270);
    this.Controls.Add(this.gridControl1);
    this.Controls.Add(this.checkBox1);
    this.Name = “Form1”;
    this.Text = “Form1”;
    this.Load += new System.EventHandler(this.Form1_Load);
    ((System.ComponentModel.ISupportInitialize)(this.gridControl1)).EndInit();
    ((System.ComponentModel.ISupportInitialize)(this.columnManagerRow1)).EndInit();
    ((System.ComponentModel.ISupportInitialize)(this.dataRowTemplate1)).EndInit();
    this.ResumeLayout(false);

    }
    #endregion

    /// <summary>
    /// The main entry point for the application.
    /// </summary>
    [STAThread]
    static void Main()
    {
    Xceed.Grid.Licenser.LicenseKey = “SAMPLE-APPLICATION-KEY”;
    Application.Run(new Form1());
    }

    private void Form1_Load(object sender, System.EventArgs e)
    {
    nFixedColumns = 5;
    data = new string[20][];
    for (int i = 0 ; i < data.GetLength(0); i++)
    {
    data[i] = new string[30];
    for (int j = 0; j < data[i].GetLength(0); j++)
    {
    data[i][j] = j.ToString();
    }
    }
    gridControl1.DataSource = data;
    }

    private void gridControl1_FirstVisibleColumnChanged(object sender, System.EventArgs e)
    {
    if (this.checkBox1.Checked)
    {
    //The nFixedColumns int contains the number of columns that should fixed.
    //n means the n first columns need to be on screen always.
    //columns are named “0” “1” “2” … initially.
    int nTel = 0;
    int nFilPos;
    if (gridControl1.FirstVisibleColumn != null)
    {
    nTel = gridControl1.FirstVisibleColumn.VisibleIndex;
    //We known the name of the first column is “0”.
    // This column should be made visible again
    // as should column “1”, “2” etc up to nFixedColumns
    nFilPos = gridControl1.Columns[“0”].VisibleIndex;
    //if the position of what should be visible is less than the first
    //visible column…
    if (nFilPos < nTel)
    {

    Imported from legacy forums. Posted by marc (had 3205 views)

    User (Old forums)
    Member
    Post count: 23064

    Same issue here..I get the same error: An attempt was made to update the PaintManager while it is already updating.

    Imported from legacy forums. Posted by Papo (had 268 views)

    User (Old forums)
    Member
    Post count: 23064

    I used to get that problem a lot. You arent calling that from a thread other than the main thread are you? I have a program where I am constantly updating the grid, and if it isnt done in a form timer, i get that error all day long.

    I thought I had a fix to keeping the columns in order

    While superTrim(MainGrid.FirstVisibleColumn.Title) <> “score”
    MainGrid.Columns(“col1”).VisibleIndex = MainGrid.FirstVisibleColumn.VisibleIndex
    MainGrid.Columns(“col2”).VisibleIndex = MainGrid.FirstVisibleColumn.VisibleIndex + 1
    MainGrid.Columns(“col3”).VisibleIndex = MainGrid.FirstVisibleColumn.VisibleIndex + 2
    MainGrid.Columns(“col4”).VisibleIndex = MainGrid.FirstVisibleColumn.VisibleIndex + 3
    MainGrid.Columns(“col5”).VisibleIndex = MainGrid.FirstVisibleColumn.VisibleIndex + 4
    End While

    but now it is freezing on certain computers…

    Imported from legacy forums. Posted by Mike (had 3545 views)

Viewing 3 posts - 1 through 3 (of 3 total)
  • You must be logged in to reply to this topic.