Hey,
I want to copy data from an excel sheet to my Grid using CTRL-C and CTRL - V.
Please anybody tell me the complete method to do so. I have read the formums and blogs but still unable to copy-paste.
As people are telling to use: e.Layout.Override.AllowMultiCellOperations = AllowMultiCellOperation.All
this line still does not helped me.
Regards
Mudassar
Hi Mudassar,
If you set AllowMultiCellOperation in the grid to all, the grid should accept pasting date from Excel. There's nothing else you need to do. But of course, the grid must be editable and there may be certain restrictions on making sure the selection types match up.
What exactly is the problem you are having? When you paste in the grid, does anything happen? Are you getting an error?
Hello Mike,
I set the property UltraGrid1.DisplayLayout.Override.AllowMultiCellOperations = AllowMultiCellOperation.All but when I select any row and then I click CTRL-C nothing ocurrs.
Why it can posibly?
I need this functionality.
Thank in advance.
Pablo Lammardo
Hi Pablo,
I still don't understand the problem. Pressing CTRL+C will not have any visible effect, it's just a copy. So how do you know it's not working? I thought you were talking about pasting from Excel into the grid, not copying FROM the grid.
Hi,
I'm also trying to paste the content from Excel to ultragrid, its allowing to paste only the same number of rows present in ultragrid not more than that. So can you please tell me how to add any number of rows from excel to ultragrid at runtime.
I'm also trying to accomplish this and am having problems.
For example, my grid currently contains a total of 5 rows. I've copied 6 from Excel, and try to paste them into my UltraGrid. I end up getting an Infragistics dialog box stating:
---------------------------Paste Error---------------------------Error performing Paste operation. Further information: Contents being pasted have more rows than what's available starting from the anchor cell. Paste contents have 6 rows where as the available rows starting from the anchor cell are 5.
---------------------------OK ---------------------------
I would expect that there should be a setting to allow pasting of additional rows, but I have yet to find it.
Thanks
Here is some VB code to add new rows before a paste based on information in clipboard:
Private Sub UltraGrid1_BeforePerformAction(ByVal sender As Object, ByVal e As Infragistics.Win.UltraWinGrid.BeforeUltraGridPerformActionEventArgs) Handles UltraGrid1.BeforePerformAction If e.UltraGridAction = UltraWinGrid.UltraGridAction.Paste Then Dim activeRow As UltraWinGrid.UltraGridRow = Me.UltraGrid1.DisplayLayout.ActiveRow Dim reader As New StringReader(Clipboard.GetText()) Dim line As String = reader.ReadLine() While (line <> Nothing AndAlso line.Trim <> String.Empty) If Me.UltraGrid1.Rows.Count - 1 = Me.UltraGrid1.DisplayLayout.ActiveRow.Index Then Me.UltraGrid1.DisplayLayout.Bands(0).AddNew() Else Me.UltraGrid1.PerformAction(UltraWinGrid.UltraGridAction.NextRow) End If line = reader.ReadLine End While activeRow.Activate() End If End Sub
can you write it in VB please
regards
Rami Quttaineh
there is one way to automaticly add new rows according to your clipboard
I've realized what you quested by doing this:
private void ultraGrid1_BeforePerformAction(object sender, Infragistics.Win.UltraWinGrid.BeforeUltraGridPerformActionEventArgs e) { if (e.UltraGridAction == Infragistics.Win.UltraWinGrid.UltraGridAction.Paste) { const string PatternLine = @"\s*(?<str>\w*)\s*"; const RegexOptions rOption = RegexOptions.IgnoreCase; Regex r = new Regex(PatternLine, rOption); MatchCollection m = null;
Infragistics.Win.UltraWinGrid.UltraGridRow iniRow = this.ultraGrid1.DisplayLayout.ActiveRow; StringReader strReader = new StringReader(Clipboard.GetText()); StringBuilder strBuilder = new StringBuilder(); string line = strReader.ReadLine(); while (line !=null) { m=r.Matches(line); if (m.Count == 1) { strBuilder.AppendLine(m[0].Result("${str}")); } else if(m.Count >= 2) { strBuilder.AppendLine(m[0].Result("${str}") + "\t" + m[1].Result("${str}")); }
if (ultraGrid1.Rows.Count - 1 == this.ultraGrid1.DisplayLayout.ActiveRow.Index) { this.ultraGrid1.DisplayLayout.Bands[0].AddNew(); } else { this.ultraGrid1.PerformAction(Infragistics.Win.UltraWinGrid.UltraGridAction.NextRow); } line = strReader.ReadLine(); } Clipboard.SetText(strBuilder.ToString()); iniRow.Activate(); } }
Hi Paul,
This has not been added as far as I know.
Any idea if this feature will be added in the WinGrid control in the near future?
Thanks,Paul