This project is read-only.

Virtual grid help

Nov 4, 2009 at 10:45 AM


I have previously developed a real neat app using a real grid, but it turned out that I needed to allocate a huge grid quickly, and I decided to convert it to a Virtual grid, and this is when I encountered lots of problems with finding the right way of doing things in documentation. In particular, 

How do you change the font and backcolor of a grid cell dynamically? For real grid, I would just assign a view with predefined FGColor and BackColor to the grid1[i,j].view and that was it.

However, for virtual grid it didn't work, and I ended up just using



            public virtual object GetValue(CellContext cellContext)

             public object GetValue(CellContext cellContext)




                cellContext.Cell.View.ForeColor = bOverLimit? Color.Red : Color.Green;

                cellContext.Cell.View.BackColor = Color.Blue;



This worked fine for background, but foregraund gets messed up a lot, so now  I see it is not going to work.


My second question is how do you convert a cell to a button and back dynamically. For some reason, virtual button is an abstract class.

The third question (once I am asking ) is how to place the grid into a real only state, when the annoying textbox does not show up oncellclick.

Overall, the documentation says "it works exactly as grid" but it looks like it is a bit of exaggeration... may be a small sample would be very helpful. I looked at existing samples, but they are all real grid, are not they.

I really appreciate any feedback, but still will keep looking for solutions myself too.





Nov 6, 2009 at 8:02 AM

1. There is sample 29, which creates background and foreground colours.

See ConditionView.EvaluateFunction delegate, it has a parameter "object itemRow". With this you can implement dynamic different colours, not static as in the sample

2. SourceGrid.Cells.Button class has this constructor:

public Button(object p_Value):base(p_Value)
            View = Views.Button.Default;

So, try assigning a differnet view, and you should get what you want. Of course, it will be more difficult, since in DataGrid there are no real cells, only virtual cells, that is, one cell shared for all the cells which are seen for user. So, probably, you will have to implement a custom cell which would does exactly what you want.


3. I did not get the question. If you want to make grid readonly, then disable editing for each cell in the grid. This can be controlled with cell.Editor.EnableEdit property


4. Documentation is not maintained at the moment, so i would be very glad if someone would help improve it

Nov 6, 2009 at 2:22 PM

Thank you so much for the detailed reply.

I addressed the situation by returning a separate ICellVirtual for each FGColor/BgColor combination I needed. In this way I do not need to assign, I just substitute the right cell to achieve the proper formatting.

I will play with making the buttons later. I couldn't figure out the meaning for AutoSize values (there is more than in docs)

I wanted to be able to size the columns separately in the virtual grid, which AutoSizeMode should it be?

I borrowed some code from the Arraygrid sample (below), and it keeps the same size for all columns.

            private SourceGrid.AutoSizeMode mAutoSizeMode = SourceGrid.AutoSizeMode.Default;

          public override SourceGrid.AutoSizeMode GetAutoSizeMode(int row)
                return mAutoSizeMode;

3. I made it read only by setting cell.Editor=null; for the aspect controlling cells I am using.

4. May be, wiki - style documentation could be usefull, because it could be maintained and extended by the community.