Home › Forums › WinForms controls › Xceed Grid for WinForms › How can I change the background/foreground color of a cell being edited?
-
AuthorPosts
-
#17337 |
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 = numericEditorImported from legacy forums. Posted by Morgan (had 2278 views)
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,
Imported from legacy forums. Posted by Ghislain (had 1257 views)
This does not seem to work because the GridControl1.SelectionBackColor still overrides the cell’s background color.
Imported from legacy forums. Posted by Morgan (had 390 views)
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.
Imported from legacy forums. Posted by Ghislain (had 2075 views)
-
AuthorPosts
- You must be logged in to reply to this topic.