Hi, Is there a possibility to get the selected rows of one grid and put them inside the data source of another grid?I know that I need to use this line code:Ultragrid1.SelectedRows = Ultragrid1.Rows(0)Ultragrid2.Datasource =? But I don't know if it's correct, because i don't know how then to insert it inside the data source.Thanks
Hello Camilla,
You can insert the selected rows of one grid to another by obtaining its selected rows collection and then adding it to a data source of your choice. In the case of the sample that I am attaching, I am using data table as the data source of the second grid. For each selected row, a data row is created in the data table, after that the data row is populated by the contents of the cells of the row that is being iterated and then the data table is assigned as the data source for the grid and the rows collection is cleared.
Please test it on your side and let me know how it behaves. If this is not an accurate demonstration of what you are trying to achieve please feel free to modify it and send it back to me along with steps to reproduce.
Additionally, if you want to add rows to the selected rows collection programmatically you can do this by using the following line:
ultraGrid1.Selected.Rows.Add(ultraGrid1.Rows(1))
Let me know if you have any questions.
Regards, Ivan Kitanov
LoadSelectedRowsToAnotherGrid.zip
Hi,
I create a sub for selected rows like this:
Private Sub SelectedRows_GRD3()
Dim dt As DataTable = New DataTable() For Each row In GRD3.Selected.Rows Dim datarow As DataRow = dt.Rows.Add() datarow(0) = row.Cells("DESCRI").Value datarow(1) = row.Cells("U_ARPRZL").Value datarow(2) = row.Cells("P1").Value datarow(3) = row.Cells("QTA").Value
Next
grd3_stampa.DataSource = dt GRD3.Selected.Rows.Clear()
End Sub
but give me an error like " System.IndexOutOfRangeException :impossible to found column 0"
How I can do?
If the secondary grid has only certain fields of the primary one, then you can add only those fields that are required for the secondary grid. For example, if you take the fields in the sample provided above, the primary grid consists of 3 fields (ID, Name and Age) and if the second grid needs information about the ID and the Name, then the Age field should be excluded from the data table and the data to the secondary grid can be filled like this:
For Each row In ultraGrid1.Selected.Rows
Dim dataRow As DataRow = dt.Rows.Add()
dataRow(0) = row.Cells(“ID”).Value
dataRow(1) = row.Cells(“Name”).Value
Please let me know if you have any questions.
It still gives problems because the secondary grid takes only certain fields with respect to the original one.
I don't know how to explain it better.
The reason why you are getting this error is because there are no columns added to the data table that you are using for data source of grd3_stampa grid. To resolve this issue, you simply need to add the following lines:
dt.Columns.Add("DESCRI", GetType(“your desired type”))
dt.Columns.Add("U_ARPRZL", GetType(“your desired type”))
dt.Columns.Add("P1", GetType(“your desired type”))
dt.Columns.Add("QTA", GetType(“your desired type”))