How i can change checkBox Style

Posted by: samo3889 on 18 February 2018, 10:50 am EST

  • Posted 18 February 2018, 10:50 am EST

    Hi all

    i use c1FlexGridClassic

    when i add new row that contain checkbox value , CheckBox Painted in blue by default (When its value is dbnull.valu)

    look at the following attachment BlueCheckBox.PNG

    there any idea how i can change the style?

    thanks

    Saleem J.

  • Posted 19 February 2018, 7:36 am EST

    Hi Saleem!

    I would like to inform you, at my end, default colour is black for painting CheckBox, as demonstrated in the attached sample (with the latest builds). I have bound the grid to a data source having at least one boolean column.

    I’m not sure of the cause behind getting blue coloured CheckBox at your end. Also, there is no direct way to control styling of these CheckBox instances in this scenario.

    If you can share your stripped-down sample with me, I hope to give you an appropriate solution for this.

    Prj_CheckBoxStyle_Classic.zip

    Thanks,

    Meenakshi

  • Posted 19 February 2018, 9:26 am EST

    hi Meenakshi

    That’s the result I get:

    any way there any idea how i can change style of db.null checkbox To be like unchecked checkbox instead Painted in blue ?

    i want DBNull.Value and False Value make the same checkbox (without to convert dbnull.value to false).

    thanks

    Saleem j.

  • Posted 20 February 2018, 2:53 am EST

    Hi Saleem!

    I am unable to replicate the issue (with 2017-V3 builds).

    Since the shared sample reproduces this colour issue at your end only. It might be related with display settings of your machine.

    In addition, if you want to use unchecked CheckBox for false as well as DBNull.Value then the only way seems to change DBNull.Value to false at back-end. Both the values are treated differently while painting on the control.

    Best regards,

    Meenakshi

  • Posted 20 February 2018, 4:45 am EST

    ok thanks Meenakshi :slight_smile:

  • Posted 20 February 2018, 6:05 am EST

    Hi Saleem,

    She is right.[quote=“meenakshi.singh”]

    if you want to use unchecked CheckBox for false as well as DBNull.Value then the only way seems to change DBNull.Value to false at back-end. Both the values are treated differently while painting on the control.

    [/quote]

    However, I found a solution for you.

    You can host a CheckBox control in C1FlexGridClassic for achieving your requirement if you want and change the cell data accordingly.

        public partial class Form1 : Form
        {
            public Form1()
            {
                InitializeComponent();
            }
            DataTable dt = null;
            private void Form1_Load(object sender, EventArgs e)
            {
                dt = new DataTable();
                dt.Columns.AddRange(new DataColumn[] { new DataColumn("Id", typeof(int)), new DataColumn("InStock", typeof(Boolean))});
                for (int i = 1; i < 11; i++)
                {
                    dt.Rows.Add(new object[] { 1, "True" });
                    dt.Rows.Add(new object[] { 2, "False" });
                    dt.Rows.Add(new object[] { 3, DBNull.Value });
                }
                
                c1FlexGridClassic1.Paint += C1FlexGridClassic1_Paint;
                c1FlexGridClassic1.DrawMode = DrawModeEnum.OwnerDraw;
                c1FlexGridClassic1.OwnerDrawCell += C1FlexGridClassic1_OwnerDrawCell;
                c1FlexGridClassic1.DataSource = dt;
                c1FlexGridClassic1.AllowUserResizing = AllowUserResizeSettings.flexResizeBoth;
                
            }
            private void C1FlexGridClassic1_Paint(object sender, PaintEventArgs e)
            {
                foreach (CheckBox cb in c1FlexGridClassic1.Controls)
                {
                    RowColumn rowColumn = cb.Tag as RowColumn;
                    Rectangle rg = c1FlexGridClassic1.GetCellRect(rowColumn.Row, rowColumn.Col);
                    cb.Size = new Size(rg.Size.Width - 2, rg.Size.Height - 2);
                    cb.Location = new Point(rg.Location.X + 1, rg.Location.Y + 1);
                }
            }
            private void C1FlexGridClassic1_OwnerDrawCell(object sender, OwnerDrawCellEventArgs e)
            {
                if (e.Col == 2)
                {
                    Type type = c1FlexGridClassic1.GetData(e.Row, e.Col)?.GetType();
                    if (type?.Name == "DBNull")
                    {
                        foreach (CheckBox cb1 in c1FlexGridClassic1.Controls)
                        {
                            if (cb1.Name == e.Row + "" + e.Col)
                            {
                                return;
                            }
                        }
                        CheckBox cb = new CheckBox();
                        cb.Name = e.Row + "" + e.Col;
                        cb.Click += Cb_Click;                    
                        cb.Size = new Size(e.Bounds.Size.Width - 2, e.Bounds.Size.Height - 2);
                        cb.Location = new Point(e.Bounds.Location.X + 1, e.Bounds.Location.Y + 1);
                        cb.CheckAlign = ContentAlignment.MiddleCenter;
                        cb.Tag = new RowColumn()
                        {
                            Row = e.Row,
                            Col = e.Col
                        };                    
                        c1FlexGridClassic1.Controls.Add(cb);
                    }
                }
            }
    
            private void Cb_Click(object sender, EventArgs e)
            {
                RowColumn rowColumn = (sender as CheckBox).Tag as RowColumn;
                c1FlexGridClassic1.Select(rowColumn.Row, rowColumn.Col);
                c1FlexGridClassic1.SetData(rowColumn.Row, rowColumn.Col, (sender as CheckBox).Checked);   
                
                //Uncomment this line if you want to remove this checkbox for next occurence
                //c1FlexGridClassic1.Controls.Remove((sender as CheckBox));
    
                c1FlexGridClassic1.Invalidate();
            }
        }
        public class RowColumn
        {
            public int Row { get; set; }
            public int Col { get; set; }
        }
    

    Thanks,

    Singh

Need extra support?

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

Learn More

Forum Channels