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

[Solved] Set a row editable and then place cursor inside the first cell

1 Answer 141 Views
GridView
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
Yolanda
Top achievements
Rank 1
Yolanda asked on 22 Sep 2010, 08:30 AM
Hello,
I have a grid of this type;

<views:PricingRadGridView x:Name="radGridViewBaseTarification" Grid.Row="1" IsBusy="True" AutoGenerateColumns="False" RowEditEnded="radGridViewBaseTarification_RowEditEnded"                        DataLoaded="radGridViewBaseTarification_DataLoaded" >
 
   <views:PricingRadGridView.Columns>
    <telerikGridView:GridViewDataColumn HeaderCellStyle="{StaticResource GridViewHeaderCellStyle}" IsVisible="False" UniqueName="EditColumn">
     <telerikGridView:GridViewColumn.CellTemplate>
        <DataTemplate>
          <telerik:RadButton Content="Edit" Style="{StaticResource RadButtonHyperlinkStyle}" Click="RadButtonEdit_Click" x:Name="RadButtonEdit"/>
        </DataTemplate>
     </telerikGridView:GridViewColumn.CellTemplate>
    </telerikGridView:GridViewDataColumn>
 
    <telerikGridView:GridViewDataColumn HeaderCellStyle="{StaticResource GridViewHeaderCellStyle}" IsVisible="False" UniqueName="CancelEditColumn">
     <telerikGridView:GridViewColumn.CellTemplate>
      <DataTemplate>
       <telerik:RadButton Content="Cancel" Style="{StaticResource RadButtonHyperlinkStyle}" Click="RadButtonEdit_Click" x:Name="RadButtonCancelEdit"/>
      </DataTemplate>
     </telerikGridView:GridViewColumn.CellTemplate>
    </telerikGridView:GridViewDataColumn>
    <telerikGridView:GridViewDataColumn Header="Prix Base" HeaderCellStyle="{StaticResource GridViewHeaderCellStyle}" DataMemberBinding="{Binding PrixBase}" x:Name="CellPrixBase" />
 </views:PricingRadGridView.Columns>
</views:PricingRadGridView>

When the user clicks on the cell "Edit" the button "Cancel" appears and the Row should turn on editable. The cursor should be also placed on the first row (PrixBase in this exemple).

For the moment the control associated to the "Edit" button is:

private void RadButtonEdit_Click(object sender, RoutedEventArgs e)
      {
         RadButton myClickedButton = (RadButton)sender;
              if (radGridViewBaseTarification.IsReadOnly == true)
              {
                  //the user can edit now the gridview
                  //radGridViewBaseTarification.IsReadOnly = false;
                  myClickedButton.Content = "Save Changes";
                  RadGridViewBaseTarification.Columns["CancelEditColumn"].IsVisible = true;
              }
              else//the user wants to save the changes
              {
                  myClickedButton.Content = "Edit";
                  radGridViewBaseTarification.IsReadOnly = true;
 
                  //save changes in the DB
 
              }



If I write radGridViewBaseTarification.IsReadOnly == false all the grid view is editable. How can I only set my selected line editable?

And how can I place the cursor over the cell "Prix base" for the row I want to edit? I've read some of the samples in the forum but in all of them the user places the cursor on a specific row (22 for exemple)

Thanks for your help

1 Answer, 1 is accepted

Sort by
0
Milan
Telerik team
answered on 22 Sep 2010, 11:03 AM

Hi Yolanda,

You could try the following: First set IsReadOnly of the grid to false - in this particular case we will manually handle which items can be edited:

object editedItem = null;
  
private void RadButtonEdit_Click(object sender, RoutedEventArgs e)
{
    RadButton myClickedButton = (RadButton) sender;
    // set the data item of the current row as edit Item
    this.editedItem = myClickedButton.DataContext;
    if (radGridViewBaseTarification.IsReadOnly == true)
    {
        //the user can edit now the gridview
        //radGridViewBaseTarification.IsReadOnly = false;
        myClickedButton.Content = "Save Changes";
        RadGridViewBaseTarification.Columns["CancelEditColumn"].IsVisible = true;
    }
    else//the user wants to save the changes
    {
        myClickedButton.Content = "Edit";
        radGridViewBaseTarification.IsReadOnly = true;
  
        //save changes in the DB
  
    }
}
  
private void RadButtonCancel_Click(object sender, RoutedEventArgs e)
{
    this.editedItem = null;
}
  
void playersGrid_BeginningEdit(object sender, GridViewBeginningEditRoutedEventArgs e)
{
    var item = e.Row.DataContext;
  
    // cancel editing if the currently edited item is not the one that we expect
    if (item != this.editedItem)
    {
        e.Cancel = true;
    }
}



Sincerely yours,
Milan
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
Yolanda
Top achievements
Rank 1
Answers by
Milan
Telerik team
Share this question
or