locked
LightSwitch - Button To Update Selected Row RRS feed

  • Question

  • Hi All

    Firstly, huge apologies I have searched around but am unsure if what I found is what I am looking for. Its frustrating as I'm sure this is really easy and once I see it, Ill know it straight away.

    To the question;

    I currently have a JobStatus column inside a datagrid. Each job starts at 'New'.

    On each row there is a button for 'In Progress' and 'Complete'.

    I would really love if the button press would update the status of the selected job (to complete or in progress).

    Any ideas?

    Edit: I am using C# :)


    • Edited by Pringlesbug Sunday, January 19, 2014 5:28 PM
    Sunday, January 19, 2014 4:49 PM

Answers

  • Hi Pringlesbug,

    Assuming you've got something like a Job entity thus a table called Jobs and one of the properties is a String called Status. On the Grid->commands, in your Screen you've added two buttons In Progress and Complete and these appear on your grid.

    The hint you re looking for in the button's execute code is :- this.Jobs.SelectedItem.Status = "Complete";

    By clicking on the button in the grid you automatically select the row thus the SelectedItem.

    Hope this points you in the right direction.

    Keith.


    E tenebris lux. ±

    • Marked as answer by Angie Xu Monday, January 27, 2014 7:42 AM
    Monday, January 20, 2014 12:11 AM
  • O dear! Shame on me. One thing I forgot was that in all "Computed ..." code you should check for the entity's existence. So what I recommend you do is:

    if(this.Jobs.SelectedItem != null)

    {

       this.Jobs.SelectedItem.Status = "Complete";

    }

    Just so you can see when this may happen, simply Add a new Job. Without the if statement you'd be cursing me.

    :-)


    E tenebris lux. ±

    • Marked as answer by Angie Xu Monday, January 27, 2014 7:42 AM
    Monday, January 20, 2014 12:33 AM

All replies

  • Hi Pringlesbug,

    Assuming you've got something like a Job entity thus a table called Jobs and one of the properties is a String called Status. On the Grid->commands, in your Screen you've added two buttons In Progress and Complete and these appear on your grid.

    The hint you re looking for in the button's execute code is :- this.Jobs.SelectedItem.Status = "Complete";

    By clicking on the button in the grid you automatically select the row thus the SelectedItem.

    Hope this points you in the right direction.

    Keith.


    E tenebris lux. ±

    • Marked as answer by Angie Xu Monday, January 27, 2014 7:42 AM
    Monday, January 20, 2014 12:11 AM
  • O dear! Shame on me. One thing I forgot was that in all "Computed ..." code you should check for the entity's existence. So what I recommend you do is:

    if(this.Jobs.SelectedItem != null)

    {

       this.Jobs.SelectedItem.Status = "Complete";

    }

    Just so you can see when this may happen, simply Add a new Job. Without the if statement you'd be cursing me.

    :-)


    E tenebris lux. ±

    • Marked as answer by Angie Xu Monday, January 27, 2014 7:42 AM
    Monday, January 20, 2014 12:33 AM
  • Mind, then again there wouldn't be a button in the grid to press!!!

    Just remember this check when you add Computed Properties in the Job entity.

    It's been a while since I visited this forum.

    Keith


    E tenebris lux. ±

    Monday, January 20, 2014 12:37 AM
  • Hi Keith

    Huge thanks for this help! I am getting an error however :(

    Error    4    'LightSwitchApplication.Production_Screen' does not contain a definition for 'JobStatus' and no extension method 'JobStatus' accepting a first argument of type 'LightSwitchApplication.Production_Screen' could be found (are you missing a using directive or an assembly reference?)    C:\Users\Darky\Documents\Visual Studio 2013\Projects\BusinessApplication\BusinessApplication\Backup\BusinessApplication\BusinessApplication.DesktopClient\Screens\Production_Screen.lsml.cs    17    18    BusinessApplication.DesktopClient

    My code currently looks like :

    namespace LightSwitchApplication
    {
        public partial class Production_Screen
        {      
            partial void Method3_Execute()
            {
                // Write your code here.
                this.JobStatus.SelectedItem.Status = "In Progress";
            }

            partial void Method2_Execute()
            {
                // Write your code here.
                this.JobStatus.SelectedItem.Status = "Complete";
            }
        }
    }

    Saturday, February 1, 2014 8:24 PM
  • Hi Use intellisense when writing your code. Maby you where to fast and misspelled entity name

    Sven Elm

    Sunday, February 2, 2014 7:31 AM