Get BackColor value of the current cell in datagrid
Hi there,
How could I get the value of the BackColor property of the current cell in the datagrid? I'm thinking of using mouse click event to play with BackColor property of the cell.
The idea is shown:
Code:
Mouse_Down_Event( )
{
if( MyGrid.CurrentCell.BackColor == Color.Red)
MyGrid.CurrentCell.BackColor = Color.White
else
MyGrid.CurrentCell.BackColor = Red
}
I tried to override Paint() method, and work with the properties of the cell through Paint() method but it didn't work.
I tried to play around the textBox object's properties, but it didn't work.
Could anyone help me please?
*I don't mind to use either DataGrid object or FlexGrid object.
Have an enjoyable cup of coffee :).
illy Maker
Re: Get BackColor value of the current cell in datagrid
You will need to use a custom ColumnStyle. Here is an example that change the ForeColor of a cell based on a condition.
How to set the ForeColor of the text in a cell based on a condition.
You can do the same in order to change the BackColor.
Re: Get BackColor value of the current cell in datagrid
Thanks for your post. I've seen this idea before, but my lost solution(my problem) is little deffirent.
Simply, what I whant to do is:
Code:
Event Button1.Click() // instead of MouseDown event
{
if(SelectedCellRange.BackColor == Color.White)
SelectedCellRange.BackColor = Color.Red;
else
SelectedCellRange.BackColor = Color.White;
}
or like this:
Code:
Event MyGrid.CellEnter()
{
if( CurrentCell.BackColor == Color.White)
CurrentCell.BackColor = Color.Red;
else
CurrentCell.BackColor = Color.White;
}
Thanks again.
Coffee Maker
Re: Get BackColor value of the current cell in datagrid
I don't know if this is exactly what you need, but DataGrid has a property called SelectedBackColor. It will paint the whole Row when it is selected in a different color.
You cannot paint a single cell easily. Only way I can think of is by deriving from DataGridTextBoxColumn, and handle the events of the TextBox property (When you inherit from this class you have access to the actual TextBox which is shown when the user edits the cell). You can set the back color of the TextBox to Red, and override the Paint method of the Column Style to paint other back color.
Re: Get BackColor value of the current cell in datagrid