locked
How do I programmatically find a row? RRS feed

  • Question

  • I have a sales order setup, and have some line items added.

    In the line items datagrid, How could I programmatically find the oldest created record, or, the first record created, so I could use that line items description?


    • Edited by MrGlimm Saturday, January 23, 2016 3:53 AM clarification
    Saturday, January 23, 2016 3:50 AM

Answers

  • Hi MrGlimm,

    Yes, you also can add a query for your table and then use this query on screen wherever and whenever. For example, I create a query which sorted by the Id or created date. Then you can get the record that you want.

    ABC abc = this.DataWorkspace.ApplicationData.SortedRecord().FirstOrDefault();

    Best Regards,
    Weiwei

    • Proposed as answer by Angie Xu Tuesday, February 2, 2016 2:16 AM
    • Marked as answer by Angie Xu Tuesday, February 2, 2016 2:16 AM
    Tuesday, January 26, 2016 1:57 AM
    Moderator

All replies

  • Hi MrGlimm,

    According to your description, your application is a LightSwitch Desktop application, is it right?

    If you want to get the one of the records in DataGrid, please find the DataGrid control with following code. Then you can do any operations for this DataGrid, include operate one of the records.

     partial void EditableABCsGrid_Created()
            {
                // Write your code here.
                this.FindControl("grid").ControlAvailable += EditableABCsGrid_ControlAvailable;
    
            }
    
            void EditableABCsGrid_ControlAvailable(object sender, ControlAvailableEventArgs e)
            {
                DataGrid dg = (DataGrid)e.Control;
    
                //do any operations for the records in DataGrid
                
            }

    Best Regards,
    Weiwei

    Monday, January 25, 2016 10:36 AM
    Moderator
  • Weiwei,

    Thanks again for the reply! I will take a look at this functionality. Forgive me if I'm confused, but would Preprocess query also be an acceptable way of finding a certain record (row)?

    Monday, January 25, 2016 11:37 AM
  • Hi MrGlimm,

    Yes, you also can add a query for your table and then use this query on screen wherever and whenever. For example, I create a query which sorted by the Id or created date. Then you can get the record that you want.

    ABC abc = this.DataWorkspace.ApplicationData.SortedRecord().FirstOrDefault();

    Best Regards,
    Weiwei

    • Proposed as answer by Angie Xu Tuesday, February 2, 2016 2:16 AM
    • Marked as answer by Angie Xu Tuesday, February 2, 2016 2:16 AM
    Tuesday, January 26, 2016 1:57 AM
    Moderator