Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to enable a disabled control on click

I have a DevExpress grid, which is disabled on screen. When I click the control, I want it to become enabled. Right now I have a click event set up for the grid:

        private void gridPSR_Click(object sender, EventArgs e)
        {
            gridPSR.Enabled = true;
        }

This isn't working. How should I be going about this?

like image 904
Sean Smyth Avatar asked Aug 22 '14 19:08

Sean Smyth


People also ask

How do I make a disabled button clickable?

Answer. Swap your disabled attribute for aria-disabled="true" . This will allow the element to maintain most of its properties that allow you to interact with it, but still keep its disabled status and announce itself to assistive technology as such.

How do I enable/disable the button on a button?

Click 'Toggle" to make 'Button' enabled or disabled. click it, and see that that one event fires if it is enabled, and another if disabled.

How to enable/disable controls in Microsoft Power Apps?

Making a Controls (for example Text Controls, Text input, Label, Button, Dropdown Etc..) enable or disable on some conditions are very common requirement in Microsoft Power Apps. In my example, I have a text box Control in canvas App of Microsoft Power Apps and 2 Button i.e. “Enable” & “Disable”.

How to disable any control with jQuery?

To disable any control with jQuery pass true as the second argument to the .prop () method. There is an input control and a button. On the button click event I will disable the input control. Here I have a disabled input control which I will enable on the button click. Sometimes you want to keep the submit button of a form disabled.

How to react to a disabled button when it clicks?

Don't try to position a clickable element above it but wrap it with one so you won’t directly be able to click it. Assuming a button with display: inline-block set: This allows you to easily react to a click even in case of a disabled button. See FIDDLE.


2 Answers

Disabled controls do not receive windows messages, so you will never get the click message on that control. Assuming this is Winforms, you can listen for the click on the form (or whatever control is hosting this grid) and check if the click location is in the rectangle of the disabled control and then enable the control accordingly:

void Form1_MouseClick(object sender, MouseEventArgs e)
{
    if (gridPSR.ClientRectangle.Contains(e.Location))
    {
        gridPSR.Enabled = true;
    }
}
like image 100
John Koerner Avatar answered Nov 04 '22 06:11

John Koerner


I know it's an old post but for me bounds worked instead of ClientRectangle

    private void OnPanelMouseClick(object sender, MouseEventArgs e)
    {
        if ((e.Button == MouseButtons.Left) &&
             myControl.Bounds.Contains(e.Location) &&
             !myControl.Enabled)
        {
            myControl.Enabled = true;
        }
    }

Where myControl is member variable of your control instance. OnPanelMouseClick handler should be linked with MouseClick event of form or container that holds control.

like image 23
papatrexas Avatar answered Nov 04 '22 05:11

papatrexas