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

Add Edit Column in first position??

3 Answers 119 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Bastien
Top achievements
Rank 1
Bastien asked on 27 May 2011, 03:17 PM
Hello!

I want to add a column to the datagrid that will allow the user to enter in "Edit Mode" for this row. Is that possible?

I have the following code, but it's not working:
<telerik:GridViewColumn>
 <telerik:GridViewColumn.CellTemplate>
    <DataTemplate>
        <telerik:RadButton Content="Edit" Command="telerikGrid:RadGridViewCommands.BeginEdit" CommandParameter="{Binding}" />
    </DataTemplate>
 </telerik:GridViewColumn.CellTemplate>
</telerik:GridViewColumn>

This code is used inside a GridView that inherits from RadGridView.

In documentation, you also have the following code:
public MainPage()
{
          ICommand editCommand = RadGridViewCommands.BeginEdit;
          InitializeComponent();
}

But I really don't understand why we need this.... "editCommand" is never used.... (I tried to add it to the page where my grid is, but it still not works!)

Thanks for help!
Bastien

3 Answers, 1 is accepted

Sort by
0
Bastien
Top achievements
Rank 1
answered on 30 May 2011, 07:54 AM
up
0
Bastien
Top achievements
Rank 1
answered on 30 May 2011, 01:51 PM
please need some help ;-)
0
Accepted
Dimitrina
Telerik team
answered on 30 May 2011, 03:50 PM
Hello Bastien Chételat,

 The "editCommand" is never used in your project, because this command uses a parameter of selected row (or cell).
I may suggest you two approaches how to set SelectedCell:

1. Add a handler for MouseLeftButtonDown event:

this.clubsGrid.AddHandler(GridViewCell.MouseLeftButtonDownEvent, new MouseButtonEventHandler(Row_Click), true);

When click on the "Edit" button, select the first cell of the clicked row:
private void Row_Click(object sender, MouseButtonEventArgs e)
        {
            var senderElement = (FrameworkElement)e.OriginalSource;
            var clickedRow = senderElement.ParentOfType<GridViewRow>();
 
            if (clickedRow != null)
            {
                // execute logic
                clubsGrid.CurrentCellInfo = new GridViewCellInfo(clickedRow.Item, clubsGrid.Columns[1]);
            }       
        }


2. Instead of Command, you may use the click event of the RadButton like this:
private void ButtonEdit_Click(object sender, RoutedEventArgs e)
       {
           var senderElement = (FrameworkElement)e.OriginalSource;
           var clickedRow = senderElement.ParentOfType<GridViewRow>();
 
           if (clickedRow != null)
           {
               // execute logic
               clubsGrid.CurrentCellInfo = new GridViewCellInfo(clickedRow.Item, clubsGrid.Columns[1]);
           }
           clubsGrid.BeginEdit();
       }

I hope that this answers your question. If you have other questions, please do not hesitate to contact us.

All the best,
Didie
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
Tags
GridView
Asked by
Bastien
Top achievements
Rank 1
Answers by
Bastien
Top achievements
Rank 1
Dimitrina
Telerik team
Share this question
or