Usage of ImageMap property in FlexGrid Styles

Posted by: tec4.ele on 21 February 2018, 9:31 am EST

  • Posted 21 February 2018, 9:31 am EST

    Good morning, I’m using Flexgrid control in WinForms.

    I would like to show an image bounbed to cell value.

    Cell data type is bool, I have 2 images: une for when the value is true one when it’s false.

    Could you explain how to perform such a task?

    Actually my solution is not working and is listed as below:

                
    	cs = c1FlexGrid1.Styles.Add("Verified");
            cs.DataType = typeof(bool);
            cs.Display = DisplayEnum.ImageOnly;
            cs.ImageAlign = ImageAlignEnum.CenterCenter;
            cs.ImageMap = ht;
    
    

    This is my hashtable for bound data and images:

                
                Hashtable ht = new Hashtable();
                Bitmap CheckedAlarm = (Bitmap)Image.FromFile("WhenFalse.png");
                Bitmap UncheckedAlarm = (Bitmap)Image.FromFile("WhenTrue.png");
                ht.Add(false, CheckedAlarm);
                ht.Add(true, UncheckedAlarm);
    
    

    Actually it doesnt seems to work as I would because the grid continue to show a checkbox.

    Thankyou for your hints.

    Regards

  • Posted 21 February 2018, 10:12 am EST

    Hi,

    Please try to assign the Style property of Column after setting C1FlexGrid’s DataSource as follows:

        public partial class Form1 : Form
        {
            public Form1()
            {
                InitializeComponent();
            }
    
            private void Form1_Load(object sender, EventArgs e)
            {
                List<Item> list = new List<Item>();
                for (int i = 1; i < 11; i++)
                {
                    list.Add(new Item()
                    {
                        Name = "Item "+i,
                        IsVerified = i % 2 == 0 ? false : true
                    });
                }
    
                Hashtable ht = new Hashtable();
                Bitmap CheckedAlarm = (Bitmap)Image.FromFile("WhenFalse.png");
                Bitmap UncheckedAlarm = (Bitmap)Image.FromFile("WhenTrue.png");
                ht.Add(false, CheckedAlarm);
                ht.Add(true, UncheckedAlarm);
                CellStyle cs = c1FlexGrid1.Styles.Add("Verified");
                cs.Display = DisplayEnum.ImageOnly;            
                cs.ImageAlign = ImageAlignEnum.Stretch;            
                cs.ImageMap = ht;
                c1FlexGrid1.DataSource = list;
                c1FlexGrid1.Cols["IsVerified"].Style = cs;
                c1FlexGrid1.Cols["IsVerified"].AllowEditing = false;
                c1FlexGrid1.AutoSizeCols();
                c1FlexGrid1.AutoSizeRows();
            }
        }
    
        public class Item
        {
            public string Name { get; set; }
            public bool IsVerified { get; set; }
        }
    

    Hope, it will solve your issue.

    Thanks,

    Singh

  • Posted 22 February 2018, 5:30 am EST

    Hi Singh,

    thankyou for your hint, It works giving a datasource before assigning styles.

    When list of items change in lenght and in content, is there a way to

    refresh the grid without use binding mechanism?

    If I keep use datasource property, I loose the image map format.

    Thankyou, Luca

  • Posted 22 February 2018, 7:45 am EST

    Hi,

    Try to use BindingList instead of List.

    For more info go through the link below:

    https://msdn.microsoft.com/en-us/library/ms132679(v=vs.110).aspx

    Thanks,

    Singh

    DisplayImageInCell.zip

Need extra support?

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

Learn More

Forum Channels