This project is read-only.

Cell edit event

Apr 2, 2009 at 11:17 AM
Edited Apr 2, 2009 at 11:28 AM
Hi,
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!

Thanks
Tom
Apr 2, 2009 at 12:10 PM
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 1:51 PM
Hi,
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?

Thanks
Apr 2, 2009 at 3: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 3: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 4:19 PM
You are using correct method if I understood you correctly.

You can access cell 1,1 value using 
[code]
sender.Grid[1, 1].Value
[/code]
Apr 2, 2009 at 4: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)

 

{

SourceGrid.

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

 

SourceGrid.

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

 

 

return otherContext.Value.ToString();

 

}