Your Privacy Matters: We use our own and third-party cookies to improve your experience on our website. By continuing to use the website we understand that you accept their use. Cookie Policy
444
How to add UltraGridRow to UltraWinGrid.UltraGrid
posted

 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

Parents
No Data
Reply
  • 990
    Verified Answer
    posted

    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.

Children