Selecteditem in Grid - Return after refresh

Posted by: netpoint on 9 September 2017, 8:30 am EST

  • Posted 9 September 2017, 8:30 am EST


    I am using the following code to returned a grid row after a refresh (after adding child records on a modal screen). This works until I switch my grid to a Flexgrid and then the grid to does not return to previousitem it stays on the first item. How to I return to the correct row using Flexgrid

    public partial class PurchaseOrders

    public PurchaseOrderHeader previousitem;

    private void POAdded()
    // event is raised on the application's thread
    //Run the refresh code in the screen's thread

    previousitem = this.PurchaseOrderHeaders.SelectedItem;

    Application.OrderLineAdded -= new Application.RecordAdded(POAdded);



    partial void PurchaseOrderHeaders_Loaded(bool succeeded)
    if (previousitem != null)
    this.PurchaseOrderHeaders.SelectedItem = previousitem;

    partial void PurchaseOrderHeaders_Changed(NotifyCollectionChangedEventArgs e)
    Application.OrderLineAdded += new Application.RecordAdded(POAdded);

  • Replied 9 September 2017, 8:30 am EST

    Hello Steve,

    I regret the delay in our response. In case you are still looking for a response, I would request you to provide me a sample application. I tried using the code that you have provided. However, some of the events seems to be specific to your application DataModel. A sample will be helpful to investigate the issue further.

    You can send me your sample app by zipping and uploading it at our FTP site using the given credentials.
    Username: Supportftp
    Password: 123ceftp123

    Open the above FTP link in Windows Explorer and login using the credentials provided. To get the login dialog, open the link, right click on the Windows explorer and select the option 'Login As'. Copy the sample on this location.

    Once you upload the sample, please let me know the name of the zip file.

  • Replied 9 September 2017, 8:30 am EST

    Did you find a solution for this?
    I'm facing the exact same problem (FlexGrid don't honor selecteditem prop on collection while LS Data Grid does).
    Screeen class:

    private Customer _currentlySelectedCustomer = null;

    private void MyRefresh()
    _currentlySelectedCustomer = Customers.SelectedItem;

    partial void Customers_Loaded(bool succeeded)
    if (_currentlySelectedCustomer != null)
    Customers.SelectedItem = _currentlySelectedCustomer;

    Regards, Henrik
  • Marked as Answer

    Replied 9 September 2017, 8:30 am EST


    MS DataGrid for lightswitch doesn't honour selected item. For C1Flexgrid for lightswitch to honour selected item use code given below:-

    public partial class FlexibleCustomers_TablesGrid
    IContentItemProxy proxy = null;
    C1.Silverlight.FlexGrid.C1FlexGrid myFlexGrid;
    BaseDataGridControl myDataGrid;

    public Customers_Table CurrentSelectedItem = null;

    partial void FlexibleCustomers_TablesGrid_Created()
    proxy = this.FindControl("C1FlexGrid");
    var proxy1 = this.FindControl("DataGrid");

    proxy.ControlAvailable += Proxy_ControlAvailable;
    proxy1.ControlAvailable += proxy1_ControlAvailable;

    void proxy1_ControlAvailable(object sender, ControlAvailableEventArgs e)
    myDataGrid = e.Control as BaseDataGridControl;
    myDataGrid.SelectionMode = DataGridSelectionMode.Single;

    private void Proxy_ControlAvailable(object sender, ControlAvailableEventArgs e)

    myFlexGrid = e.Control as C1.Silverlight.FlexGrid.C1FlexGrid;
    myFlexGrid.SelectionMode = C1.Silverlight.FlexGrid.SelectionMode.Row;

    partial void RefreshFlexGrid_Execute()
    CurrentSelectedItem = Customers_Tables.SelectedItem;

    partial void Customers_Tables_Loaded(bool succeeded)
    Customers_Tables.SelectedItem = CurrentSelectedItem;
    Dispatchers.Main.BeginInvoke(() =>
    myFlexGrid.SelectedItem = CurrentSelectedItem;
    myDataGrid.SelectedItem = CurrentSelectedItem;

    Please have a look at the attached sample for more clarity.

    Hope it helps.

Need extra support?

Upgrade your support plan and get personal unlimited phone support with our customer engagement team

Learn More

Forum Channels