Welcome to the Xceed Community | Help
Community Search  
More Search Options

How can I change the background/foreground color of a cell being edited?

Sort Posts: Previous Next
  •  02-02-2010, 1:30 PM Post no. 25629

    How can I change the background/foreground color of a cell being edited?

    I am new to Xceed.  I have searched the forum, but could not find out how can I change the background / foreground color of a cell being edited.

    I have tried the following but the color does not change:

          Dim numericEditor As New NumericEditor
          Dim numericTextBox As WinNumericTextBox = numericEditor.TemplateControl
          numericTextBox.BackColor = Color.Yellow
          GridControl1.Columns.Add(New Column("UnitCost", GetType(Single)))
          GridControl1.Columns("UnitCost").CellEditorManager = numericEditor

     

    Filed under:
  •  02-02-2010, 11:53 PM Post no. 25636 in reply to 25629

    Re: How can I change the background/foreground color of a cell being edited?

    Hi,

    You didn't mention if the cells were if value cells, data cells, insertion cells...  Also, I decided to make the grid:

    gridControl1.SingleClickEdit = true;

    so a single click on a cell gets you in edit mode.  Otherwise, things a more complicated.

    The form1.cs gives this:

    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;
    using System.Diagnostics;
    using Xceed.Grid;

    namespace TestNet40
    {
        public partial class Form1 : Form
        {
            InsertionCell lastICell = null;
            DataCell lastDCell = null;

            public Form1()
            {
                Xceed.Grid.Licenser.LicenseKey = "GRD38-.......";
                InitializeComponent();
            }

            private void Form1_Load(object sender, EventArgs e)
            {
                gridControl1.SingleClickEdit = true;
            }

            private void cell_EditEntered(object sender, EventArgs e)
            {
                Xceed.Grid.InsertionCell iCell = null;
                if (sender is Xceed.Grid.InsertionCell)
                {
                    iCell = (Xceed.Grid.InsertionCell)sender;
                    if (iCell != null)
                    {
                        gridControl1.CurrentCell.BackColor = Color.Yellow;
                        gridControl1.CurrentCell.ForeColor = Color.Blue;
                        lastICell=iCell;
                    }
                }

                Xceed.Grid.DataCell dCell = null;
                if (sender is Xceed.Grid.DataCell)
                {
                    dCell = (Xceed.Grid.DataCell)sender;
                    if (dCell != null)
                    {
                        gridControl1.CurrentCell.BackColor = Color.LightGray;
                        gridControl1.CurrentCell.ForeColor = Color.Black;
                        lastDCell = dCell;
                    }
                }
               
                Debug.WriteLine("Edit entered");
            }

            private void cell_EditLeft(object sender, EditLeftEventArgs e)
            {
                if (lastICell != null)
                {
                    lastICell.ResetBackColor();
                    lastICell = null;
                }
                if (lastDCell != null)
                {
                    lastDCell.ResetBackColor();
                    lastDCell = null;
                }
                Debug.WriteLine("Edit left");
            }
        }
    }
     

    Basically, I have put an event on the 'Edit left' and 'Edit entered' with different color depending if it's the insertion cells or the data cells.  There is certainly a way to write this more efficienly. 

    Best regards,


    Ghislain
    Technical Support and software developer
    Xceed Software Inc.
    Knowledge Base : http://xceed.com/kb/
    Update Center : http://xceed.com/updates/
    Documentation Center : http://xceed.com/doc/
    For everything else, there is Google
    Filed under: , , ,
  •  02-03-2010, 4:13 PM Post no. 25653 in reply to 25636

    Re: How can I change the background/foreground color of a cell being edited?

    This does not seem to work because the GridControl1.SelectionBackColor still overrides the cell's background color.
  •  02-04-2010, 12:34 PM Post no. 25664 in reply to 25653

    Re: How can I change the background/foreground color of a cell being edited?

           public Form1()
            {
                Xceed.Grid.Licenser.LicenseKey = "GRD38-*****-*****-****";
                InitializeComponent();
                gridControl1.SelectionBackColor = Color.White;
                gridControl1.SelectionForeColor = Color.Black;
                gridControl1.UIStyle = Xceed.UI.UIStyle.WindowsClassic;
                foreach (Column column in gridControl1.Columns)
                {
                    column.CellEditorManager.SettingControlAppearance += new Xceed.Grid.Editors.CellEditorEventHandler(CellEditorManager_SettingControlAppearance);            
                }           
            }

            void CellEditorManager_SettingControlAppearance(object sender, Xceed.Grid.Editors.CellEditorEventArgs e)
            {
                e.Control.BackColor = Color.Yellow;
                e.Control.ForeColor = Color.Black;
            }

    We are limited in the way we can help you.   The line gridControl1.UIStyle = Xceed.UI.UIStyle.WindowsClassic; is important for your application to look the same on operating systems prior to Vista and also on Vista and Windows 7.


    Ghislain
    Technical Support and software developer
    Xceed Software Inc.
    Knowledge Base : http://xceed.com/kb/
    Update Center : http://xceed.com/updates/
    Documentation Center : http://xceed.com/doc/
    For everything else, there is Google
    Filed under: ,
View as RSS news feed in XML
Contact | Site Map | Reviews | Legal Terms of Use | Trademarks | Privacy Statement Copyright 2011 Xceed Software Inc.