How to handle Click Event by a row

Jul 26, 2009 at 11:37 AM

Hi,

I'm a new user of this fantastic grid.

I have a simple question, I think but in the examples I haven't found it.

I know how I can handle a click on a single Cell but I need that when a row

is clicked my application show a Message that have the value of the first Cell

of the selected row and not the value of the selected Cell.

Can you help to solve this?

Thanks

 

Panthe

Jul 26, 2009 at 6:53 PM
Edited Jul 26, 2009 at 6:54 PM

Hi,

I too am a new user and have only been playing with the grid for a few days.  I completely agree with you that SourceGrid is superb!

From your post I'm not sure whether you want to detect moving to a new row or detect any click on a row regardless of whether it's a different row or not.

If you just want to detect clicking away from the current row you could use the event Grid.Selection.FocusRowEntered.  RowEventArgs.Row gives the new row.

Another possible solution is to write a controller that overrides ControllerBase.OnClick(CellContext sender, EventArgs e).  I would expect CellContext.Position.Row to give you the row you clicked on.

Hope I've been of some help,

Clarry

 

 

Jul 26, 2009 at 7:01 PM

What do you mean exactly, when you mean "when the row is clicked"? A click on the row header (first column at the left) or on any cell of the row?

In practice, you'll ave to manage it as ClarryDadoo said: add a Controller to the row headers or to every cellsand get the row number with sender.Position.Row.

And with sender.Grid... you will be able to get the value of the first cell of the row.

Jul 26, 2009 at 10:05 PM

Hi guys,

thanks for your reply.

For explain better what I want do with the SourceGrid...

I want that when the user click on any cell of the row it's shown a message with the text displayed on the first cell of the row only.

I have add this controller:

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

and I have override the event OnClick

public class CellClickEvent : SourceGrid.Cells.Controllers.ControllerBase
        {
            public override void OnClick(SourceGrid.CellContext sender, EventArgs e)
            {
                base.OnClick (sender, e);
    
                MessageBox.Show(sender.Grid.Selection. , sender.DisplayText);
            }
        }

I know that for get the number of row I can use this instruction:

sender.Position.Row

but I don't know how I can get the value of the first cell of this row.

Can you help me?

Thanks a lot...

;-)

Jul 26, 2009 at 10:12 PM

Oopppsss..

I have tried and I have found this solution.

sender.Grid.GetCell(sender.Position.Row,0).ToString()

The result is exactly what I wanted.

Great ;-)