We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy.
Unfortunately, activation email could not send to your email. Please try again.

Swapping controls in two cells

Thread ID:

Created:

Updated:

Platform:

Replies:

21206 Nov 4,2004 07:50 AM Nov 4,2004 12:42 PM Windows Forms 5
loading
Tags: GridControl
Colin Marsh
Asked On November 4, 2004 07:50 AM

I am having problems moving controls i.e. swapping controls from two cells. I can reproduce the problem quite easy in a simple test application. Description: When I swap controls in cell A & B so that controlB is in CellA and controlA is in CellB then the grid begins to behave abnormally, I can''t select one of the cells and it will not repaint correctly. To Reproduce the problem: Create a quick c# windows application, drag a menu on the form and create one option, then drag a GridControl on to the form. In the constructor create two progess bar controls (These are simply the easiest controls to create the issue with, I know there are progress bars cells). Set one controls value 10 10 and the other to 100 so you can visually see the difference. Place them in two cells e.g. 1,1 and 1,2. Then when the user click the menu option swap the controls in the cells: Control tempControl = mTestGrid[1,1].Control; mTestGrid[1,1].Control = mTestGrid[1,2].Control; mTestGrid[1,2].Control = tempControl; Now try to select the cells with the control. Notice that one of the cells will not activate. For example select a clear cell then select one of the cells with progress bar. One will activate and you can see that the selection highlight moves. Go back to the clear cell and select the other progess bar. The cell does not activate and the selection highlight does not move from the clear cell. Keep swapping and you will eventually see a repain issue. The weird thing is if you do this with a button, the cell will fix itself. But a control that does not interact like a button is essentially hung. I am placing graphs in cells and they are not displaying properly after I move them from one cell to another.

Administrator [Syncfusion]
Replied On November 4, 2004 10:09 AM

I did not set up the sample to try this, so it may not work. Try setting GridStyleInfoStore.ControlProperty.IsCloneable = false; By default the style clones it properties when making assignments. In this case, you seem to want to use the reference to the same bject, and not a clone. (As the cloning method may not persist things like the current value of teh control).

Colin Marsh
Replied On November 4, 2004 11:45 AM

Did not help much. There are still repainting issues. By doing this, the cell does look correct to view it. But if anaything is drawn over the cell (e.g. a context menu), the cell still does not repaint properly. More importantly, you still can not activate the cell. By clicking on the cell, the cell does not get focus. Small test app if you want: public class Form1 : System.Windows.Forms.Form { private System.Windows.Forms.MainMenu mainMenu1; private System.Windows.Forms.MenuItem menuItem1; private System.Windows.Forms.MenuItem menuItem2; private Syncfusion.Windows.Forms.Grid.GridControl mTestGrid; /// /// Required designer variable. /// private System.ComponentModel.Container components = null; public Form1() { // // Required for Windows Form Designer support // InitializeComponent(); GridStyleInfoStore.ControlProperty.IsCloneable = false; ProgressBar pb1 = new ProgressBar(); pb1.Value = 10; ProgressBar pb2 = new ProgressBar(); pb2.Value = 100; mTestGrid[1,1].CellType = "Control"; mTestGrid[1,1].Control = pb1; mTestGrid[1,2].CellType = "Control"; mTestGrid[1,2].Control = pb2; } /// /// Clean up any resources being used. /// protected override void Dispose( bool disposing ) { if( disposing ) { if (components != null) { components.Dispose(); } } base.Dispose( disposing ); } #region Windows Form Designer generated code /// /// Required method for Designer support - do not modify /// the contents of this method with the code editor. /// private void InitializeComponent() { this.mainMenu1 = new System.Windows.Forms.MainMenu(); this.menuItem1 = new System.Windows.Forms.MenuItem(); this.menuItem2 = new System.Windows.Forms.MenuItem(); this.mTestGrid = new Syncfusion.Windows.Forms.Grid.GridControl(); ((System.ComponentModel.ISupportInitialize)(this.mTestGrid)).BeginInit(); this.SuspendLayout(); // // mainMenu1 // this.mainMenu1.MenuItems.AddRange(new System.Windows.Forms.MenuItem[] { this.menuItem1}); // // menuItem1 // this.menuItem1.Index = 0; this.menuItem1.MenuItems.AddRange(new System.Windows.Forms.MenuItem[] { this.menuItem2}); this.menuItem1.Text = "&File"; // // menuItem2 // this.menuItem2.Index = 0; this.menuItem2.Text = "&Option 1"; this.menuItem2.Click += new System.EventHandler(this.menuItem2_Click); // // mTestGrid // this.mTestGrid.Location = new System.Drawing.Point(0, 0); this.mTestGrid.Name = "mTestGrid"; this.mTestGrid.Size = new System.Drawing.Size(292, 208); this.mTestGrid.SmartSizeBox = false; this.mTestGrid.TabIndex = 0; this.mTestGrid.Text = "gridControl1"; // // Form1 // this.AutoScaleBaseSize = new System.Drawing.Size(5, 13); this.ClientSize = new System.Drawing.Size(408, 457); this.Controls.Add(this.mTestGrid); this.Menu = this.mainMenu1; this.Name = "Form1"; this.Text = "Form1"; ((System.ComponentModel.ISupportInitialize)(this.mTestGrid)).EndInit(); this.ResumeLayout(false); } #endregion /// /// The main entry point for the application. /// [STAThread] static void Main() { Application.Run(new Form1()); } private void menuItem2_Click(object sender, System.EventArgs e) { Control tempControl = mTestGrid[1,1].Control; mTestGrid[1,1].Control = mTestGrid[1,2].Control; mTestGrid[1,2].Control = tempControl; } }

Colin Marsh
Replied On November 4, 2004 11:58 AM

Here''s a weird one, the problem only occurs when you have one of the cells selected that you are swapping. And it happens in the cell you have selected. So if you have 1,1 selected, after swapping, that cell will not activate. If you have 1,2 selected, after you swap, 1,2 wont activate. If you have 3,3 selected and you swap it works fine. I can create a work around, but I''d like to know how to avoid the problem. Thanks

Administrator [Syncfusion]
Replied On November 4, 2004 12:12 PM

When a Control celltype is not active, you are actually looking at a bitmap picture of the control, and not really the control. When the cell is active, then you do see the control positioned at the cell location. If you want to swap out the control in this manner, it might be reasonable to make sure neither is the active cell during the swap. You may have to handle an active current cell as a special case. The reason is that the style information stored in the grid is used to initialize the current cell. So, changing the style while the cell is current, does not change what was used to initialize the current cell and so the current cell retains its old setting (and can cause things to be out of sync).

Administrator [Syncfusion]
Replied On November 4, 2004 12:42 PM

This code avoided the problem in your sample for me. GridCurrentCell cc = this.mTestGrid.CurrentCell; cc.Deactivate(false); Control tempControl = mTestGrid[1,1].Control; mTestGrid[1,1].Control = mTestGrid[1,2].Control; mTestGrid[1,2].Control = tempControl; cc.Activate(cc.RowIndex, cc.ColIndex);

CONFIRMATION

This post will be permanently deleted. Are you sure you want to continue?

Sorry, An error occured while processing your request. Please try again later.

You are using an outdated version of Internet Explorer that may not display all features of this and other websites. Upgrade to Internet Explorer 8 or newer for a better experience.

;