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

Paste GridView

4 Answers 81 Views
GridView
This is a migrated thread and some comments may be shown as answers.
David
Top achievements
Rank 2
David asked on 11 Sep 2012, 03:34 PM
Hi,

I'm trying to paste data into a GridView. What i want to do is user clicks new line clicks ctl+v then I handle the Pasting event on the grid to paste my data.

The issue is, when the user clicks the new row and presses the ctl+v the data is pasted into the selected cell

is it possible to deselect the cell so that the paste event is fired

thanks
 
David

4 Answers, 1 is accepted

Sort by
0
Yoan
Telerik team
answered on 14 Sep 2012, 10:46 AM
Hi David, 

 In order to achieve your goal you can subscribe to BeginningEdit event and cancel it. Check the following code snippet:

private void radGridView_BeginningEdit( object sender, Telerik.Windows.Controls.GridViewBeginningEditRoutedEventArgs e )
{
    e.Cancel = true;
}

Please tell me if that works for you? Greetings,
Yoan
the Telerik team

Time to cast your vote for Telerik! Tell DevPro Connections and Windows IT Pro why Telerik is your choice. Telerik is nominated in a total of 25 categories.

0
David
Top achievements
Rank 2
answered on 14 Sep 2012, 11:20 AM
Hi,

Thanks, This will cancel any edit so the user wouldn't be able to edit any data. I could check if the row is a new row but that would also leave the user unable to manually enter data into the new line.

What I need is if the user clicks the add new row section then it adds the blank row but doesn't put the first cell into edit. Then if the user clicks on a cell it would go into edit mode.

is this possible?

thanks

Daivd
0
Yoan
Telerik team
answered on 19 Sep 2012, 10:40 AM
Hello David ,

 Please find attached a sample project according to your requirements. Tell me if this works for you.

Regards,
Yoan
the Telerik team

Time to cast your vote for Telerik! Tell DevPro Connections and Windows IT Pro why Telerik is your choice. Telerik is nominated in a total of 25 categories.

0
David
Top achievements
Rank 2
answered on 20 Sep 2012, 07:53 AM
Hi, 

Thanks for the example it didnt fit quite what I wanted but I have made a few changes and it seems to be working ok

 I removed the CommitEdit so that it didnt just add a new row and then remove the beginningedit handler and add an ended event so that until i end the edit on the new row any cell i click will be editable but not currently selected.

This then allows me to handle the paste and add my own logic to the paste

Thanks Again.

David

private void radGridView1_BeginningEdit(object sender, Telerik.Windows.Controls.GridViewBeginningEditRoutedEventArgs e)
{
    this.radGridView1.BeginningEdit -= radGridView1_BeginningEdit;
    if (this.radGridView1.Items.CurrentAddItem == e.Row.Item)
    {
        e.Cancel = true;
    }
    //this.radGridView1.CommitEdit();

    this.radGridView1.RowEditEnded += radGridView1_RowEditEnded;
     
}
 
void radGridView1_RowEditEnded(object sender, Telerik.Windows.Controls.GridViewRowEditEndedEventArgs e)
{
    this.radGridView1.RowEditEnded -= radGridView1_RowEditEnded;
    this.radGridView1.BeginningEdit += radGridView1_BeginningEdit;
}
 
private void radGridView1_Pasting_1(object sender, Telerik.Windows.Controls.GridViewClipboardEventArgs e)
{
    //ToDo Invoke VM Paste
    e.Cancel = true;
    e.Handled = true;
}
Tags
GridView
Asked by
David
Top achievements
Rank 2
Answers by
Yoan
Telerik team
David
Top achievements
Rank 2
Share this question
or