且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

剪贴板:将数据从Excel复制到gridview

更新时间:2023-11-02 23:44:58

我认为你的问题在这里:

I think your problem is here:
List<string> cellsList = new List<string>();
    string[] cells = lines[x].Split('\t');

    cellsList.AddRange(cells);

    table.Add(cellsList);







为了创建你应该做的事情:




In order to create the table you should perhaps do something lik:

string[] lines = importText.Split('\r');
          for (int x = 0; x < lines.Length; x++)
                sting[] cell = lines.Split('\t')
                for (int y = 0; x < cell.Length; x++)</pre>


试试这个



请参考以下链接



DataGridView-Copy-and-Paste


解决方案非常简单,



我只需添加e.Handle就像这样:



The solution is quite simple,

I just add e.Handle like this :

PasteData(Clipboard.GetText());
e.Handle = true;





这意味着所有进入都由humain处理。



事实上,问题来自这样一个事实:它不仅创建了从表格到gridview的表格和复制数据,而且还处理了Ctrl + V,其中meands复制了某些内容或输入了charV也是。





感谢您的帮助!!



this means that all enters with be handled by humain.

In fact, the problem comes from the fact that it not only created table and copy data from the table to gridview, but also handled the "Ctrl + V" which meands copied something or entered the char "V" as well.


Thank you for all your help!!