Paste from excel

4 posts, 0 answers
  1. Vaggelis Charalabakis
    Vaggelis Charalabakis avatar
    5 posts
    Member since:
    May 2010

    Posted 12 Jul 2010 Link to this post

    How can i paste columns from an ecel to my gridview?

    Is it possible when this gridview is bounded to a dataset?

  2. Martin Vasilev
    Admin
    Martin Vasilev avatar
    1061 posts

    Posted 15 Jul 2010 Link to this post

    Hi Vaggelis Charalabakis,

    Thank you for writing.

    Your question is actually more related to MS Excel since the key feature in your scenario concerns the way Excel interacts with the clipboard. For additional details about the Excel specifics, please refer to this MSDN article. The rest of the implementation is related to the way you handle the clipboard information and the way you use the content to modify RadGridView. You can find a sample implementation of a copy/paste scenario in this knowledge base article.

    In regards to your second question, yes, you are able to add columns to a databound RadGridView.

    Let me know if you have any other questions.

    Sincerely yours,
    Martin Vasilev
    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
  3. UI for WinForms is Visual Studio 2017 Ready
  4. Andreas Haeusler
    Andreas Haeusler avatar
    25 posts
    Member since:
    Nov 2009

    Posted 22 Mar 2011 Link to this post

    As the mentioned knowledge base article does not cover the handling of clipboard data from Excel here's my modification of that code - for the purpose of copy/pasting data from Excel to a RadGridView. A pre-Q3 - 2010 Version might need replacing of TableElement with GridElement.

    Hope it is of any use.

    private void PasteRows(RadGridView radGridView)
           {
               //fetch tabstop-separated Data from clipboard
               IDataObject dataObj = Clipboard.GetDataObject();  
               if (dataObj != null)
               {
                   var clipBoard = dataObj.GetData(DataFormats.Text).ToString();
                   if (clipBoard != string.Empty)
                   {
                       if (radGridView.TableElement != null) radGridView.TableElement.BeginUpdate();
                       var lineSeparator = new String[] {Environment.NewLine};
                       string[] lines = clipBoard.Split(lineSeparator, Int32.MaxValue, StringSplitOptions.None);
                       int i = 0;
                       try
                       {
                           foreach (var line in lines)
                           {
                               string[] cellVal = line.Split('\t');
                               //
                               // Create and add Object to datasource using values in cellVal[xxx];
                               //
                           }
                       }
                       catch (Exception ex)
                       {
                           MessageBox.Show("Incompatible DataSources");
                       }
                       radGridView.TableElement.EndUpdate();
                   }
               }
           }
  5. Martin Vasilev
    Admin
    Martin Vasilev avatar
    1061 posts

    Posted 25 Mar 2011 Link to this post

    Hi Andreas,

    Thank you for sharing your code with us. I have updated your Telerik points for your community participation. Do not hesitate to contact us if you have any other questions.

    Best wishes,
    Martin Vasilev
    the Telerik team
Back to Top