Your Privacy Matters: We use our own and third-party cookies to improve your experience on our website. By continuing to use the website we understand that you accept their use. Cookie Policy
1960
Disable EditorButton in an UltraNumericEditor that is set as the EditorComponent
posted

Hi,

My grid has an int column with an UltraNumericEditor (UNE) assigned to it. The UNE has two AutoRepeatEditorButtons in the ButtonsRight collection. One of the buttons is called "Plus" and increments the value of the editor. The other button is called "Minus" and decrements the value of the editor.

The editor is set as the EditorComponent of my int column. I want to disable the Plus button when the Column.MaxValue is reached or the Minus button when the Column.MinValue is reached. I tried with the code below but it doesn't seem to work.

When I run that code I see the button disabled in the UNE but it's still enabled in the cell.

Any ideas?

 

private void ultraGrid2_CellChange(object sender, CellEventArgs e)

{

if (e.Cell.Column.Key == "NuemricColumn")

{

bool minButtonEnabled = true;

bool maxButtonEnabled = true;

decimal decimalValue = 0;

if (decimal.TryParse(e.Cell.GetText(MaskMode.Raw), out decimalValue) == true)

{

if (e.Cell.Column.MinValue != null)

{

decimal minVal = Convert.ToDecimal(e.Cell.Column.MinValue);

if (decimalValue <= minVal)

{

minButtonEnabled = false;

}

}

 

if (e.Cell.Column.MaxValue != null)

{

decimal maxVal = Convert.ToDecimal(e.Cell.Column.MaxValue);

if (decimalValue >= maxVal)

{

maxButtonEnabled = false;

}

}

}

UltraNumericEditor numericEditor = e.Cell.EditorComponentResolved as UltraNumericEditor;

numericEditor.ButtonsRight["Plus"].Enabled = maxButtonEnabled;

numericEditor.ButtonsRight["Minus"].Enabled = minButtonEnabled;

}

}

Parents
  • 469350
    Verified Answer
    Offline posted

    Hi,

    The problem here is that you are setting the Enabled property on the button that exists in the UltraNumericEditor control. But the grid doesn't use the control. The control simply provides a copy of it's internal editor to the grid.

    So you need to get the EditorResolved property on the cell, instead of EditorComponentResolved. You can cast the editor into an EditorWithMask (or EmbeddableEditorButtonBase if you want to do this in a more generic way) and then get the ButtonsRight collection from there.

    In fact, you really don't need to use an UltraNumericEditor control for this. It would be more efficient to use an EditorWithMask.

    But either way, the problem with the approach you are taking here is that the buttons enabled state applies to all cells in the column. So the buttons will only get enabled/disabled when the user makes a change to a cell. Then when the user moves to another cell, or simply moves the mouse over another cell, the enabled states won't get updated and the buttons will not look right (or work right) until after the user makes a change.

    What I would do is use a CreationFilter to enable the UIElements for the buttons. CreationFilters can be a bit tricky if you haven't used them before. So I whipped up a small sample and I am attaching it here so you can check it out.

     

     

    WindowsFormsApplication58.zip
Reply Children
No Data