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

Get Current Row number

2 Answers 273 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Asaduzzaman
Top achievements
Rank 1
Asaduzzaman asked on 13 Jul 2010, 11:12 AM
In my silverlight Radgridview I want add new row when user press enter key or press tab from keyboard.
The new row will be added only when user is in gridview last row , I also want to get the gridview current row number in RowEditEnded event.
Is there any way to check unique value in Gridview column from client side like in my gridview SSN column should be unique for adding and edit data.

Thanks

Azad

2 Answers, 1 is accepted

Sort by
0
Maya
Telerik team
answered on 13 Jul 2010, 02:07 PM
Hi Asaduzzaman,

What you can do is to handle the KeyDown event and in case the key used is "Tab" to call the method BeginInsert(). Furthermore, you need to handle the AddingNewDataItem event. For example:

private void playersGrid_KeyDown(object sender, KeyEventArgs e)
        {
            if (e.Key == Key.Tab)
            {
                var grid = sender as RadGridView;
                Player currentItem = grid.CurrentItem as Player;
                if ((currentItem != null))
                {
                    grid.BeginInsert();
                    grid.CurrentColumn = grid.Columns[0];
                }
                else
                {
                    e.Handled = true;
                }
            }
        }
 
        private void playersGrid_AddingNewDataItem(object sender, Telerik.Windows.Controls.GridView.GridViewAddingNewEventArgs e)
        {
            e.NewObject = new Player();
        }

In the RowEditEnded event, you can call CommitEdit() so that the newly created item is added. In order to take the index of the CurrentItem, you may use the the following:
this.playersGrid.Items.IndexOf(this.playersGrid.CurrentItem)

As for checking if the value of a certain field is unique, you may handle the event CellValidating, walk through all the items and compare their values.
I am sending you a sample project illustrating the proposed solution.
However, here only the "Tab" key is managed as the "Enter" is a little bit more specific. So, in order to provide you with a possible solution for this case too, we would need more details about your requirements and expectations when this button is clicked.



All the best,
Maya
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
0
Asaduzzaman
Top achievements
Rank 1
answered on 15 Jul 2010, 06:28 AM
Thanks it's work alright..


Tags
GridView
Asked by
Asaduzzaman
Top achievements
Rank 1
Answers by
Maya
Telerik team
Asaduzzaman
Top achievements
Rank 1
Share this question
or