If you select rows from a grid on one form and are trying to copy those selected rows to a grid on another form how would you accomplish this?
I'm trying the code below but the selected rows never copy over. I've tried using
loTable = oTable.Copy but this copies every row from the current grid instead of just the selected rows. Any help would be appreciated.
Private Sub cmdMerge_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdMerge.Click
Dim oTable As DataTable
Dim loTable As DataTable
Dim oItem As Infragistics.Win.UltraWinGrid.UltraGridRow
Try
Cursor.Current = Cursors.WaitCursor
If uGridMain.Selected.Rows.Count < 2 Then
MessageBox.Show(
"You must select at least two(2) " & AddressAlias & " records to be merged.", "Merge Error", MessageBoxButtons.OK, MessageBoxIcon.Exclamation)
Exit Sub
End If
Dim oForm As New frmMergeRecords
oTable = uGridMain.DataSource
loTable = oTable.Clone
oForm.uGridMain.DataSource = loTable
For Each oItem In uGridMain.Selected.Rows
oForm.uGridMain.BeginUpdate()
For intI As Integer = 1 To oItem.Cells.Count - 1
If TypeOf oItem.Cells(intI).Value Is Boolean Then
oForm.uGridMain.Rows.TemplateAddRow.Cells(intI).Value = oItem.Cells(intI).Value
Else
oForm.uGridMain.Rows.TemplateAddRow.Cells(intI).Value = oItem.Cells(intI).Text
Next
oForm.uGridMain.EndUpdate()
oForm.Text =
"Merge " & AddressAlias
oForm.AddressMerge =
True
oForm.ShowDialog()
LoadListView()
Catch ex As Exception
HandleError(ex, Name,
"cmdMerge_Click" )
Finally
Cursor.Current = Cursors.Default
End Try
End Sub
This code is really hard to read - our forums apparently don't like copying and pasting from Visual Studio on some machines. You might want to post a small sample project or maybe paste your code into Notepad and then copy it from there so it strips out the formatting.
I don't see anything obviously wrong with the code you have here. It looks like you are looping through the selected rows in the first grid and copying the values into the second grid.
You are using the TemplateAddRow, which is a bit odd, though. You are essentially copying the rows via the user interface, which is a strange thing to do in code. There are certainly more efficient and easier ways to do it.
Are you trying to have the second grid show only the selected rows in the first grid? Or do you want to add the selected rows to the existing rows in the second grid?
Why are you changing the DataSource on the main grid?
Yes, I am trying to only show the selected rows from the first grid in the second grid. And unless I'm missing something I'm not changing the datasource on the main grid but I am setting the datasource on the other forms grid.