Hello all,
Is there a way that the WebGrid will allow you to programatically look at the clipboard contents prior to calling WebGrid.paste()?
The functionality I'm trying to accomplish here is to add more rows and/or columns to an existing grid in order to compensate for sizing correctly from data copied from an Excel spreadsheet...
For example, I have a grid that is 6 rows by 6 columns, and if I paste in data copied from Excel with more rows or columns, the grid ignores the additional columns.
So what I would like to do is to determine the rows and/or columns I need to add to the WebGrid (this should be doable on the client side?) by taking a look at the content on my clipboard (again, on the client side), and correctly resizing the WebGrid before the data is pasted.
I know about the BeforeClipboardOperation, I just need to get at the clipboard data! I'm using IE, so I have snooped around and there appears to be a way to grab clipboard data via javascript from IE, but I was wondering if there is some feature I don't know about in the WebGrid that will allow me to do this.
Thanks so much!
Mike
Hi, the article you posted is entitled "HOWTO:Copy selected rows from a WebGrid to Excel using the clipboard"... I need to do the exact opposite, copy excel data into the WebGrid, but I need to perform validation on the data before just dropping it into the grid...
I ended up using the Microsoft javascript extension that comes with IE:window.clipboardData.getData
which is not the solution I really wanted, but it seems it's the only way for me to validate data before just dropping it into the grid. Since the WebGrid cannot "resize itself" to the amount of rows that are pasted from the clipboard (the grid already needs to have the empty rows there, or you pasted data will stop at the last row in the grid even if there is more data on the clipboard), I needed to find a way to make the webgrid take the data.
First, I tried adding the addition rows client-side based on the rows on the clipboard, and that seemed to work fine until postback, and that's when I realized the grid did not know about these new rows I added, b/c it was client side... which was useless.
so now when I paste into the grid, I use the BeforeClipboardOperation event, read my data from the clipboard, validate, then write the data to a hidden input field and call igtbl_doPostBack.
Then on page postback, after the grid has been bound, I check my hidden field for any additional data, and end up adding the rows, and then the data to those rows server side before the grid is rendered.
Again, not the most elegant of solutions, but it does appear to be working so far. A wish of mine for future WebGrid versions is to allow the grid to resize itself based on what is pasted into it, instead of making the developer doing all the work.
If there is something I'm doing wrong, or if anyone has a better idea of how to go about doing what I'm doing, the WebGrid is a beast of an application, and it's quite possible I could be missing something here...
Thanks,Mike
Hi Mike,
Look at the following article, you can choose the rows and columns that you are copying.
http://devcenter.infragistics.com/Support/KnowledgeBaseArticle.aspx?ArticleID=9849
Magued