Click here to Skip to main content
15,886,362 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Good day
Could you please help, I am using EF 4.0 windows application c#. I am battling to display imagebackground on dynamically loaded button. your help will be much appreciated.
2 my code
C#
int i = 1;

            foreach (TabPage tp in tabControl1.TabPages)
            {

                ObjectQuery<tblproduct> listProduct = new ObjectQuery<tblproduct>("SELECT VALUE P FROM TblProducts AS P WHERE P.ProductType = " + i.ToString(), afNewObject);
                
                FlowLayoutPanel flp = new FlowLayoutPanel();
                flp.Dock = DockStyle.Fill;
               
                foreach (TblProduct tprod in listProduct)               
                {
                    Button b = new Button();
                    b.Size = new Size(100, 100);
                    b.Text = tprod.Description;
                    
                    b.BackgroundImage = tprod.Image; // error line
                   
                    b.Tag = tprod;
                   
                    b.Click += new EventHandler(UpdateProductList);
                  
                    flp.Controls.Add(b);
                }

                tp.Controls.Add(flp);
                i++;
Posted
Updated 6-Sep-15 6:53am
v2
Comments
What is the error?
Baitshoki 8-Sep-15 8:22am    
Error - Cannot implicitly convert type 'byte[]' to 'System.Drawing.Image'
1. column name is "Image" and type is Money in my database.
2. line of code coursing error
b.BackgroundImage = tprod.Image; // error line

Thanks in advance
You should have a Image dayatype for this, not money. Try with Image datatype.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900