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

Paste from excel

3 Answers 140 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Vaggelis Charalabakis
Top achievements
Rank 1
Vaggelis Charalabakis asked on 12 Jul 2010, 04:34 PM
How can i paste columns from an ecel to my gridview?

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

3 Answers, 1 is accepted

Sort by
0
Martin Vasilev
Telerik team
answered on 15 Jul 2010, 04:17 PM
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
0
Andreas Haeusler
Top achievements
Rank 2
answered on 22 Mar 2011, 10:55 PM
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();
               }
           }
       }
0
Martin Vasilev
Telerik team
answered on 25 Mar 2011, 12:19 PM
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
Tags
GridView
Asked by
Vaggelis Charalabakis
Top achievements
Rank 1
Answers by
Martin Vasilev
Telerik team
Andreas Haeusler
Top achievements
Rank 2
Share this question
or