I have 2 UltraGrids on a form. Say, select some rows on Grid1, and click on the button to see these selected rows on Grid =2.
When user clicks the button, I have all the rows selected on Grid 1 in SelectedRowsCollection Object. Now how do I add these UltraGridRows collection to Grid2.
UltraGrid1.DataSource does not accept SelectedRowsCollection.
I cannot even directly convert/cast each UltraGridRow to DataRow, place it in DataTable and and assign that datatable to Grid's DataSource.
I don't even see something like Grid2.Rows.Add(UltraGridRow)
How do I display those selected rows in Grid1 on Grid2?
Please help me find a solution.
Thanks,
Sindhu
Hi Sindhu,
The key to this is to recognise that an UltraGrid must be bound to a DataSource which is why there is no UltraGrid.Rows.Add method. You can bind to something as simple as a System.ComponentModel.BindingList<>:
private BindingList<Customer> _copiedCustomers = new BindingList<Customer>();
Then bind the list to the grid:
Grid2.DataSource = _copiedCustomers;
Once you have done that you can enumerate the selected rows from Grid1 using:
foreach (UltraGridRow row in Grid1.Selected.Rows)
{
...
}
Then you can examine the row and use the ListObject property to obtain the actual object from Grid1:
Customer customer = (Customer)row.ListObject;
Then add the object to your binding source of Grid2:
_copiedCustomers.Add(customer);
Hope this makes sense. If you need more details let me know.
Cheers,
Andy.
Hey thanks for the help. It worked. And looking at that I even did something different and event that worked. Its:
//Declare a TEMP dataTable, dNewTable
// ADD columns to it.
Dim m_pRow As DataRow For Each gridRow As UltraGridRow In grid1.Selected.Rows m_pRow = dNewTable.NewRow() m_pRow.ItemArray = CType(gridRow.ListObject, DataRowView).Row.ItemArray dNewTable.Rows.Add(m_pRow) Next
grid1.DataSource = dNewTable