0

I have a winform powerpacks datareapter control having a picture box. This is the code snippet from the classes.

DisplaySystemUsersControl.Designer.cs

this.picBoxUserImage.BorderStyle = System.Windows.Forms.BorderStyle.Fixed3D;
this.picBoxUserImage.DataBindings.Add(new System.Windows.Forms.Binding("Image", this.UserBindingSource, "User_Image", true));
this.picBoxUserImage.Location = new System.Drawing.Point(3, 3);
this.picBoxUserImage.Name = "picBoxUserImage";
this.picBoxUserImage.Size = new System.Drawing.Size(100, 93);
this.picBoxUserImage.SizeMode = System.Windows.Forms.PictureBoxSizeMode.StretchImage;
this.picBoxUserImage.TabIndex = 0;
this.picBoxUserImage.TabStop = false;
this.picBoxUserImage.Click += new System.EventHandler(this.picBoxUserImage_Click);

DisplaySystemUsersControl.cs

public DisplaySystemUsersControl()
{
    InitializeComponent();
    this.dataRepeaterAccounts.DataSource = this.UserBindingSource;
    LoadAccountData();
}    

private void LoadAccountData()
{
    SystemUserBusinessClass oSystemUserBusinessClass = new SystemUserBusinessClass();
    List<SystemUserEntity_Only_For_UI_Binding> obj = oSystemUserBusinessClass.GetSystemUsersForUI();

    BindingSource tempUserBindingSource = (BindingSource)dataRepeaterAccounts.DataSource;
    obj.ForEach(oSystemUserEntity_Only_For_UI_Binding => tempUserBindingSource.Add(oSystemUserEntity_Only_For_UI_Binding));
}

SystemUserEntity_Only_For_UI_Binding.cs

public class SystemUserEntity_Only_For_UI_Binding
{
    public string User_Id { get; set; }

    public string User_Name { get; set; }

    public byte[] User_Image { get; set; }
}

User ID and User name is getting loaded. But Image is not getting loaded. SystemUserEntity_Only_For_UI_Binding.User_Image() is holding the image byte array.

Can anybody please tell me what is going wrong?

Joel
  • 7,401
  • 4
  • 52
  • 58
mlg
  • 1,162
  • 1
  • 14
  • 32
  • I don't see `this.picBoxUserImage.Image` being set anywhere in your sample code. – LarsTech Feb 05 '12 at 13:54
  • @LarsTech - I am setting the binding property in the designer class. `this.picBoxUserImage.DataBindings.Add(new System.Windows.Forms.Binding("Image", this.UserBindingSource, "User_Image", true));` – mlg Feb 05 '12 at 14:08
  • Are you converting the byte array to an image somewhere? – LarsTech Feb 05 '12 at 14:50
  • I tried with converting the byte array into image . Still it is not binding. – mlg Feb 05 '12 at 17:53

2 Answers2

0

Your class should look something like this:

public class SystemUserEntity_Only_For_UI_Binding
{
  public string User_Id { get; set; }
  public string User_Name { get; set; }
  public Image User_Image { get; set; }
}

The byte array needs to be translated into an image somewhere in your code:

using (MemoryStream ms = new MemoryStream(imgBytes)) {
  this.User_Image = Image.FromStream(ms);
}
LarsTech
  • 80,625
  • 14
  • 153
  • 225
  • I tried this code also. But unfortunately it is not working. I used this code. This is working. `private void dataRepeaterAccounts_DrawItem(object sender, DataRepeaterItemEventArgs e) { Image img; img = ((SystemUserEntityOnlyForUIBinding)((BindingSource)((DataRepeater)sender).DataSource).Current).User_Image; ((PictureBox)e.DataRepeaterItem.Controls["picBoxUserImage"]).Image = img; }` – mlg Feb 06 '12 at 05:32
  • If that is working, please create a new answer and mark it as the right answer. – Joel May 08 '13 at 18:48
-3
public void BindRepeater (DataSet dsObj)
{
   pictureBox1.DataBindings.Clear();
   pictureBox1.DataBindings.Add("ImageLocation", dt, "Photo");
   dataRepeater1.DataSource = dsObj;

 }
  • While this link may answer the question, it is better to include the essential parts of the answer here and provide the link for reference. Link-only answers can become invalid if the linked page changes. – Bjørn-Roger Kringsjå Sep 12 '15 at 15:24
  • //assuming dataset has required fields public void BindRepeater (DataSet dsObj) { pictureBox1.DataBindings.Clear(); pictureBox1.DataBindings.Add("ImageLocation", dt, "Photo"); //ImageLocation is the property of the pictureBox1and Photo is column name in dataset dataRepeater1.DataSource = dsObj; } – user5328294 Sep 12 '15 at 15:51