We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy.
Unfortunately, activation email could not send to your email. Please try again.

Pasting into multiple cells

Thread ID:

Created:

Updated:

Platform:

Replies:

5796 Jul 17,2003 03:08 PM Aug 11,2004 06:03 AM Windows Forms 5
loading
Tags: GridControl
Joshua Johnson
Asked On July 17, 2003 03:08 PM

Microsoft Excel allows me to select multiple cells and paste a value into the selected cells. How is that possible with Syncfusion Grid Control?

Jamie Hill
Replied On July 17, 2003 03:51 PM

I too had the same problem. I came up with this solution, but there might be something else better. This will handle the ClipboardPaste event and call another function which returns a boolean value for whether or not the paste was handled. There is alot of conditional checking to see if the paste is a single row and/or single column. This allows for a big blob of data to still be pasted into the grid, while handling the case of pasting one piece of data into multiple cells. JH Private Sub DataGrid1_ClipboardPaste(ByVal sender As Object, ByVal e As Syncfusion.Windows.Forms.Grid.GridCutPasteEventArgs) Handles DataGrid1.ClipboardPaste Dim blnHandled As Boolean blnHandled = ClipboardPaste(DataGrid1) e.Handled = blnHandled End Sub Private Function ClipboardPaste(ByVal dg As Grid.GridControl) As Boolean Try Cursor = Cursors.WaitCursor Dim intRow, intCol As Integer Dim objRow As Grid.GridRangeInfo Dim objRange As Grid.GridRangeInfo = dg.Selections.Ranges.ActiveRange ' Declares an IDataObject to hold the data returned from the clipboard. ' Retrieves the data from the clipboard. Dim iData As IDataObject = Clipboard.GetDataObject() Dim strText() As String 'If there is more than one row, return false so that the paste can proceed. strText = Split(CType(iData.GetData(DataFormats.Text), String), vbNewLine) If strText.GetUpperBound(0) > 1 Then Return False Exit Function End If 'If there is more than one column, return strText = Split(CType(iData.GetData(DataFormats.Text), String), vbTab) If strText.GetUpperBound(0) > 0 Then Return False Exit Function End If 'If the paste is a single cell, return false so that the paste can proceed. If objRange.Top = objRange.Bottom And objRange.Left = objRange.Right Then dg(dg.CurrentCell.RowIndex, dg.CurrentCell.ColIndex).Text = "" Return False End If 'Loop through the selected rows and paste the value into each cell. For intRow = objRange.Top To objRange.Bottom Try Cursor = Cursors.WaitCursor 'Paste into each cell for the row. For intCol = objRange.Left To objRange.Right 'MessageBox.Show(intRow.ToString & " " & intCol.ToString) ' Determines whether the data is in a format you can use. If iData.GetDataPresent(DataFormats.Text) Then 'Put the clipboard value into the cell. dg(intRow, intCol).Text = CType(iData.GetData(DataFormats.Text), String) End If Next Catch ex As System.Exception MessageBox.Show(ex.ToString) Finally Cursor = Cursors.Default End Try Next Return True Catch ex As System.Exception HandleError(ex) Finally Cursor = Cursors.Default End Try End Function

Philip Bishop
Replied On August 10, 2004 12:55 PM

I was wondering if you could help me make this do one other thing its lacking on. This codes seems in early testing to work fine but if the user selects the column header cell to select the whole column then it wont paste right. If u select one cell and copy it and then select a column header and paste it, it will only paste in the first cell of the selected column. I''m using a non data bound grid in vs 2003. the cell type is currency and the activate current celle behavior is set to double click on cell. Any ideas on this???

Administrator [Syncfusion]
Replied On August 10, 2004 03:13 PM

After getting objRange, expand it so that it reflects a range of cells. objRange = objRange.Expand(1, 1, dg.RowCount, dg.ColCount)

Philip Bishop
Replied On August 11, 2004 05:51 AM

Ok so i have one last question I think on all of this. Does this process of copying one to many using that clipboardpaste function now make it so it wont go to the pastecelltext event? It appears as if it doesnt go there at all now. Is it as simple as adding the validating code to the clipboardpaste function??

Administrator [Syncfusion]
Replied On August 11, 2004 06:03 AM

Setting e.Handled = true in ClipboardPaste tells the grid that you handled the pasting, and it should not execute it''s default paste code (which raises the PasteCellText validation event). So, in this case, if you want to validate things, then you would have to initiate the validation in some manner. You could either just do it directly in your ClipboardPaste method, or you could raise an event there that listeners could subscribe to, and allow them to validate the paste.

CONFIRMATION

This post will be permanently deleted. Are you sure you want to continue?

Sorry, An error occured while processing your request. Please try again later.

You are using an outdated version of Internet Explorer that may not display all features of this and other websites. Upgrade to Internet Explorer 8 or newer for a better experience.

;