Cell edit event

Apr 2, 2009 at 10:17 AM
Edited Apr 2, 2009 at 10:28 AM
I have setup a grid with string cells, how get an event when a cell has been editted?
I have looked in the samples and everywhere! maybe its obvious but I cant see it!

Apr 2, 2009 at 11:10 AM
ok is this what you do?


public class ValueChangedEvent : SourceGrid.Cells.Controllers.ControllerBase




    public override void OnValueChanged(SourceGrid.CellContext sender, EventArgs e)




    base.OnValueChanged(sender, e);



    string val = "Value of cell {0} is '{1}'";



    MessageBox.Show(sender.Grid, string.Format(val, sender.Position, sender.Value));



grid1.Controller.AddController(new ValueChangedEvent());

Apr 2, 2009 at 12:51 PM
still having problems! i am sure it cant be this difficult!
the sender.Grid in the above is a virtual grid? so I can see to get the values from the grid?

Apr 2, 2009 at 2:45 PM
What problems do you have? You can get changed value from sender.Value, sender.Grid is grid that was edited, you can get other values if you need from it.
Apr 2, 2009 at 2:59 PM
for example:
if I have editted cell 4,4 how would I get the value of cell 1,1 ?

also am I using the right method for the cell event? by creating the event ValueChangedEvent how do I access function on the form the grid is on? i.e. refresh something when grid is editted?

I am just not convince the above can be the right method?
Apr 2, 2009 at 3:19 PM
You are using correct method if I understood you correctly.

You can access cell 1,1 value using 
sender.Grid[1, 1].Value
Apr 2, 2009 at 3:38 PM
I tried that but the code doesn't compile, I get the error
"cannot apply indexing with [] to and expression of type SourceGrid.GridVirtual"

in the end I did this little function


private string GetVal(SourceGrid.CellContext sender, int row, int col)




Position otherCell = new SourceGrid.Position(row, col);



CellContext otherContext = new SourceGrid.CellContext(sender.Grid, otherCell);



return otherContext.Value.ToString();