Copy Excel data to WinForm control listview

Source: Internet
Author: User

    1. Add a right-click menu to the form first ContextMenuStrip
    2. Add a drop-down item "Paste"
    3. Paste Event:
 Private voidTsmipaste_click (Objectsender, EventArgs e)            {listViewData.Items.Clear ();            ListViewData.Columns.Clear (); LISTVIEWDATA.COLUMNS.ADD ("",0, HorizontalAlignment.Center); LISTVIEWDATA.COLUMNS.ADD ("Serial Number", +, HorizontalAlignment.Right); LISTVIEWDATA.COLUMNS.ADD ("Courier Number", -, HorizontalAlignment.Center); LISTVIEWDATA.COLUMNS.ADD ("Modify Weight", the, HorizontalAlignment.Right); vari =0; varStrshuju ="";//the obtained stringIDataObject IData =Clipboard.getdataobject (); if(Idata.getdatapresent (Dataformats.text)) {Strshuju= (string) Idata.getdata (Dataformats.text); }            if(Strshuju.indexof ("\ r \ n") == -1)return; varIshuju = Strshuju.length;//Total string Length             while(Strshuju! ="")            {                Try                {                    varMyItem =NewListViewItem (); MYITEM.SUBITEMS.ADD ((++i).                    ToString ()); varStrrow = strshuju.substring (0, Strshuju.indexof ("\ r \ n"));//string per line                    varIRow = strshuju.substring (0, Strshuju.indexof ("\ r \ n")). Length;//string length per line                    varIRow1 =0;//string length per line                    if(IRow = =0)                         Break; IRow1= IRow +1; IRow= IRow +2; Ishuju= Ishuju-IRow; Strshuju=strshuju.substring (IRow, Ishuju); Strrow= Strrow +"\ t";  while(Strrow! ="")                    {                        varStrcolumn = strrow.substring (0, Strrow.indexof ("\ t"));//string per paragraph                        varIColumn = strcolumn.substring (0, Strrow.indexof ("\ t")). Length;//string length per segment                        if(IRow1 = =0)                             Break; IRow1= Irow1-icolumn-1; Strrow= strrow.substring (IColumn +1, IRow1);                    MYITEM.SUBITEMS.ADD (Strcolumn);                } listViewData.Items.Add (myitem); }                Catch(argumentoutofrangeexception) { Break; }            }        }

Copy Excel data to WinForm control listview

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.