locked
Button Enable/Disable when value is less than 500 RRS feed

  • Question

  • I am trying to make my button disable when the number is less than 500 and enable when it is greater than 500. The value determination I was using was based off of "intvalue". I was wondering if there is a way to code this to make it enable and disable upon this determination. 

    Monday, February 17, 2014 6:28 PM

Answers

  • Hi Calypso65, in your _Created() event in the screen, put this code, the name of the control, its your Number Control, i assumed the name is "Number", but check in your screen. 

    this.FindControl("Number").ControlAvailable += delegate(object sender, ControlAvailableEventArgs e)
    {
    	(e.Control as Textbox).SelectionChanged += disableEnable_SelectionChanged;
    };

    Then in the selectionChanged() event you need to do this:

    private void disableEnable_SelectionChanged(object sender, SelectionChangedEventArgs e)
    {
    	this.Details.Dispatcher.BeginInvoke(() =>
    	{
    		Microsoft.LightSwitch.Threading.Dispatchers.Main.BeginInvoke(() =>
    		{
    			if (this.TABLE.SelectedItem.Number > 500)
    				this.FindControl("Button_Control").IsEnabled = true;
    			else
    				this.FindControl("Button_Control").IsEnabled = false;
    		});
    	});
    }

    Hope it helps.


    • Edited by NESTicle 8Bit Monday, February 17, 2014 6:49 PM
    • Marked as answer by Angie Xu Monday, February 24, 2014 1:47 AM
    Monday, February 17, 2014 6:49 PM