I want to add multiple datatables to a datasource witout creating each time (loop) a dataset by merging the current datasource to the new datatable.
This is my code :
' Those table are the same but have different data
' Tables() array, it's an example
For Each oTable As System.Data.DataTable In Tables
DisplayResult(oTable, ColumnsAreCreated)
Next
Then I want to display the result in the grid :
Private Function DisplayResults(ByVal oTable As System.Data.DataTable, ByRef ColumnsAreCreated As Boolean) As Boolean
If oTable.Rows.Count > 0 Then
Dim compt As Integer = 0
If Not ColumnsAreCreated Then
Dim NewColumn As DevExpress.XtraGrid.Columns.GridColumn
For Each oColumn As DataColumn In oTable.Columns
NewColumn = grdv.Columns.AddField(oColumn.ColumnName)
NewColumn.OptionsColumn.ReadOnly = True
NewColumn.Visible = True
NewColumn.VisibleIndex = compt
compt += 1
Next
ColumnsAreCreated = True
' I want to do something like : grdctrl.DataSource += oTable
grdctrl.DataSource = oTable
grdv.OptionsView.ColumnAutoWidth = False
grdv.BestFitColumns()
End If
End If
Return True
End Function
I don’t want to erase each time the current data, i want to do a concatenation of the current datasource in the gird with the following datatables, one by one.
I don’t want to create a dataset, put in it the datatables and finally provide the gridcontrol the dataset.
There’s a way to do it without creating a dataset ?
If I understand you correctly you want to “merge” all results, right?
Why not simply do that before binding to the grid in a single table?
If you want to merge after binding – bind the PGrid to a data source and member “Table” and then simply use Table.Merge(AddedTable). This should also automatically update your grid.
make sure you do not set keys to the table, otherwise you will get a regular merge (values will be updated if they are different and not added)
Hope I understood the question 🙂