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
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