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. Image for the cookie policy date

Static cell content deletes

version 2.0.5.1. I have used the static cells. If i press delete key the content of the cells has been deleted. How do i prevent this? I have used cellInfo.readonly = true, but I need to rename the text in some cells. To simulate the problem 1. Run the sample code presented here. 2. Select a row (or Cell) press delete key.(The content of the entire row (or Cell) has been deleted) How could prevent this delete operation. // //Here is the sample code // using System; using System.Drawing; using System.Collections; using System.ComponentModel; using System.Windows.Forms; using System.Data; using System.Collections.Specialized; using System.IO; using Syncfusion.Windows.Forms.Grid; namespace ForumPost { /// /// Summary description for Form1. /// public class Form1 : System.Windows.Forms.Form { /// /// Required designer variable. /// private System.ComponentModel.Container components = null; private Syncfusion.Windows.Forms.Grid.GridControl gc_test; private StringCollection strChoiceList; private MenuItem mi_rename; private ContextMenu ctx_test; public Form1() { // // Required for Windows Form Designer support // InitializeComponent(); // // TODO: Add any constructor code after InitializeComponent call // ctx_test.MenuItems.AddRange( new MenuItem[]{mi_rename}); mi_rename.Click += new EventHandler(Rename_Click); ctx_test.Popup += new EventHandler(Context_Popup); strChoiceList = new StringCollection(); strChoiceList.Add("Choice1"); strChoiceList.Add("Choice2"); strChoiceList.Add("Choice3"); } /// /// 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.gc_test = new Syncfusion.Windows.Forms.Grid.GridControl(); this.ctx_test = new ContextMenu(); this.mi_rename = new MenuItem("Rename"); ((System.ComponentModel.ISupportInitialize)(this.gc_test)).BeginInit(); this.SuspendLayout(); // // gc_test // this.gc_test.Location = new System.Drawing.Point(0, 0); this.gc_test.Name = "gc_test"; this.gc_test.Size = new System.Drawing.Size(400, 176); this.gc_test.TabIndex = 0; this.gc_test.RowCount = 5; this.gc_test.ColCount = 3; // // Form1 // this.AutoScaleBaseSize = new System.Drawing.Size(5, 13); this.ClientSize = new System.Drawing.Size(480, 293); this.Controls.Add(this.gc_test); this.ContextMenu = ctx_test; this.Name = "Form1"; this.Text = "Form1"; this.Load += new System.EventHandler(this.Form1_Load); ((System.ComponentModel.ISupportInitialize)(this.gc_test)).EndInit(); this.ResumeLayout(false); } #endregion /// /// The main entry point for the application. /// [STAThread] static void Main() { Application.Run(new Form1()); } private void Form1_Load(object sender, System.EventArgs e) { for(int row=1; row<=5; row++) { AddStaticText(row,1,"Row"+row+",Col1"); AddStaticText(row,2,"Row1"+row+",Col2"); AddComboBox(row,3); } //Allign gc_test.ColWidths.ResizeToFit(GridRangeInfo.Cols(1,3), GridResizeToFitOptions.IncludeHeaders); } private void AddStaticText(int row, int col, string text) { GridStyleInfo sInfo = new GridStyleInfo(); sInfo.CellType = "Static"; // //If cell is set to ReadOnly we could not rename the text value. //sInfo.ReadOnly = true; sInfo.Text = text; sInfo.TextAlign = GridTextAlign.Right; sInfo.BackColor = SystemColors.Control; sInfo.Font.Size = 9; this.gc_test[row,col] = sInfo; } private void AddComboBox(int row, int col) { GridStyleInfo sInfo = new GridStyleInfo(); sInfo.CellType = "ComboBox"; sInfo.ExclusiveChoiceList = true; sInfo.ChoiceList = strChoiceList; //We couldnot select the choice from te list. //sInfo.ReadOnly = true; this.gc_test[row,col] = sInfo; this.gc_test[row,col].Text = strChoiceList[0]; } private void Rename_Click(object sender, EventArgs e) { gc_test[gc_test.CurrentCell.RowIndex, gc_test.CurrentCell.ColIndex].Text = "Renamed"; } private void Context_Popup(object sender, EventArgs e) { mi_rename.Enabled = false; if(gc_test.CurrentCell.HasCurrentCell) mi_rename.Enabled = true; } } }

5 Replies

AD Administrator Syncfusion Team March 15, 2005 08:20 AM UTC

Try also setting style.ReadOnly = true for these cells. When you want to change these cells, set grid.IgnoreReadOnly = true, make your change and then set IgnoreReadOnly = false to again lock the readonly cells.


AD Administrator Syncfusion Team March 15, 2005 08:51 AM UTC

Thanks clay. I have set Readonly property for static cells it works fine. Since TextBox and ComboBox need to get input from user we cannot set Style.ReadOnly=true. If you select an entire row and press delete key then the Textbox and ComboBox cells contents gets deleted. How could prevent this ?


AD Administrator Syncfusion Team March 15, 2005 09:19 AM UTC

If you never want to delete anything, then handle the ClearingCells event and set e.Handled = true;


AD Administrator Syncfusion Team March 15, 2005 09:37 AM UTC

In ClearingCells event handler i had set e.Handled=true; But it doesn''t works for ComboBox cells. Thanks in advance


AD Administrator Syncfusion Team March 15, 2005 11:34 AM UTC

If I select more than one cell, I do not see the problem. But if I just click a single combobox and press delete, then the content is cleared. If you want to avoid this behavior in the single combobox, then you will need to derive your own cell control and override OnKeyDown in the renderer. http://www.syncfusion.com/Support/user/uploads/Forum_CeleteCells2051_2afda84f.zip

Loader.
Live Chat Icon For mobile
Up arrow icon