This project is read-only.

Cells' backcolor

Apr 19, 2010 at 10:08 PM

Hi guys,

I have a tricky issue : I generate a SourceGrid (4.22) where some cells (textboxes) are spanned. Everything ok. But when I seek to change the backcolor, all cells' backolor is changed.

Here is an extract of my code :

/* Double "for" to generate my sourcegrid */

/* Determine if the cell had a special backcolor */
if //condition
   grid1[j, i] = new SourceGrid.Cells.Cell(" ", typeof(String));
   grid1[j, i].View.BackColor = Color.Tomato;
   grid1[j, i].RowSpan = lesCours[k].z;
   grid1[j, i].Value = lesCours[k].mat;
   // [...]

   grid1[j, i] = new SourceGrid.Cells.Cell(String.Empty, typeof(String));
   //grid1[j, i].View.BackColor = Color.White;
   grid1[j, i].Value = ' ';

// End for

Here, all my cells have a white blackcolor, even cells with text (if they have a text, we entered in the if)

But if I delete comments on line : grid1[j, i].View.BackColor = Color.White; this is what happens :

- While we're not in the if(), all cells' backcolors are white.

- When we enter in the if, all cell's backcolors became red, previous and next cells...

I don't really undersand what's wrong... But I use SourceGrid for few time, and maybe I didn't understand something. Could you help me ?

Thanks in advance :-)

Apr 20, 2010 at 7:53 AM

This is because all cells share the same view by default :)


you must assign a different view, and share that for all black cells, and for white cells just do nothing, that is, keep sharing the same white view

Apr 20, 2010 at 2:46 PM
Edited Apr 20, 2010 at 2:48 PM

Ok, thanks a lot, it works :-)

I look your answer and this thread to write a valid code :


See you soon