Disabled c1FlexGrid appearance

Posted by: officedtafast-co-uk on 27 September 2017, 9:15 pm EST

    • Post Options:
    • Link

    Posted 27 September 2017, 9:15 pm EST

    Hi all

    I have a c1FlexGrid on a form. I’d like to disable it unless a tickbox is checked.

    This is simple, and works.

    However, the appearance is different to other standard objects. For example, the label and textbox below the flexgrid take on the standard Windows disabled appearance, where the flexgrid appears the same. This makes it look as if it’s still enabled, but it isn’t.

    Any ideas on how to change that?

    If it’s simpler, I can just disable an entire column, as long as that appears disabled.

    Thanks

    Alex

  • Posted 27 September 2017, 9:15 pm EST

    Just adding a reply, as I forgot to tick the notify checkbox

  • Posted 27 September 2017, 9:15 pm EST

    Hello Alex,

    For changing the appearance of disabled C1FlexGrid, you need to create your CellStyle that looks similar to the standard disabled controls and apply the same to Grid cells as follows:

    [csharp]private void Form1_Load(object sender, EventArgs e)

    {

    c1FlexGrid1.DataSource = dt;

    c1FlexGrid1.Enabled = false;

            disabledStyle = c1FlexGrid1.Styles.Add("Disabled");
            disabledStyle.BackColor = Color.FromArgb(Convert.ToByte(240), Convert.ToByte(240), Convert.ToByte(240));
            disabledStyle.ForeColor = Color.DarkGray;
            disabledStyle.Border.Style = BorderStyleEnum.Flat;
            disabledStyle.Border.Color = Color.LightGray;
    
            CellRange rng = default(CellRange);
            rng = c1FlexGrid1.GetCellRange(1, 1, c1FlexGrid1.Rows.Count - 1, c1FlexGrid1.Cols.Count - 1);
            rng.Style = disabledStyle;
        }
        private void c1FlexGrid1_EnabledChanged(object sender, EventArgs e)
        {
            if (!c1FlexGrid1.Enabled)
            {
                c1FlexGrid1.VisualStyle = VisualStyle.Custom;
                CellRange rng = default(CellRange);
                rng = c1FlexGrid1.GetCellRange(1, 1, c1FlexGrid1.Rows.Count - 1, c1FlexGrid1.Cols.Count - 1);
                rng.Style = disabledStyle;
            }
            else
            {
                //apply original style or your own style.
                c1FlexGrid1.VisualStyle = VisualStyle.System;
                CellRange rng = default(CellRange);
                rng = c1FlexGrid1.GetCellRange(1, 1, c1FlexGrid1.Rows.Count - 1, c1FlexGrid1.Cols.Count - 1);
                rng.Style = c1FlexGrid1.Styles.Normal;
            }
        }[/csharp]
    

    You may then disable/enable the grid using CheckBox as follows:

    [csharp]private void c1CheckBox1_CheckedChanged(object sender, EventArgs e)

    {

    if(c1FlexGrid1.Enabled)

    {

    c1FlexGrid1.Enabled = false;

    }

    else

    {

    c1FlexGrid1.Enabled = true;

    }

    }[/csharp]

    I have also attached a sample application for your reference.

    Thanks,

    Ruchir Agarwal

    2017/08/prj_DisabledFlexGrid.zip

  • Posted 27 September 2017, 9:15 pm EST

    Thanks Ruchir

  • Posted 25 October 2017, 9:38 am EST

    Is it possible to disable certain cells in a FlexGrid?

Need extra support?

Upgrade your support plan and get personal unlimited phone support with our customer engagement team

Learn More

Forum Channels