This is a migrated thread and some comments may be shown as answers.

CellClick and Keys navigation

1 Answer 140 Views
GridView
This is a migrated thread and some comments may be shown as answers.
superold
Top achievements
Rank 1
superold asked on 26 Sep 2010, 12:06 AM
hi

i wonder what the best way to implement CellClick (which I use as a RowClick) would be when using keys for navigation. In a sence it would be optimal if the up/down/left/right keys would trigger CellClick.. 

thanks
- j

1 Answer, 1 is accepted

Sort by
0
Accepted
Emanuel Varga
Top achievements
Rank 1
answered on 26 Sep 2010, 11:38 AM
Hello Jorge,

First, i should start by saying that if you just want to be notified when the current row is changed you can just use that event (CurrentRowChanging and CurrentRowChanged), but if you prefer using the CellClick event, there are a couple of ways of doing this, from which the easiest one is to create a custom grid, inheriting from RadGridView, and just override the OnKeyDown event, like this:
public class CustomGrid : RadGridView
    {
        public override string ThemeClassName
        {
            get { return typeof(RadGridView).FullName; }
        }
 
        protected override void OnKeyDown(KeyEventArgs e)
        {
            base.OnKeyDown(e);
 
            if (this.CurrentCell != null && this.CurrentCell.RowIndex != -1 && this.CurrentCell.ColumnIndex != -1 &&
                 (e.KeyCode == Keys.Left || e.KeyCode == Keys.Right || e.KeyCode == Keys.Up || e.KeyCode == Keys.Down))
            {
                OnCellClick(this.CurrentCell, new GridViewCellEventArgs(CurrentCell.RowInfo, CurrentCell.ColumnInfo));
            }
        }

There is also another more complex solution in which you can create a new GridBehavior override there the ProcessKey event, and get the next cell there, but the problem with this is that you cannot call any event from the grid behavior...

If you need anything else or if you want to try doing things with the grid behavior please let me know and i will add that solution also, but like i told you, i haven't found a way of calling any grid events from the grid behavior...

Hope this helps,
Best Regards,
Emanuel Varga
Tags
GridView
Asked by
superold
Top achievements
Rank 1
Answers by
Emanuel Varga
Top achievements
Rank 1
Share this question
or