Powerpacks DataRepeater Control - 图像框中没有加载图像

时间:2012-02-05 12:28:01

标签: winforms picturebox datarepeater powerpacks

我有一个带有图片框的winform powerpacks datareapter控件。这是类中的代码片段。

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; }
}

正在加载用户ID和用户名。但是Image没有加载。 SystemUserEntity_Only_For_UI_Binding.User_Image()持有图像字节数组。

有人可以告诉我出了什么问题吗?

2 个答案:

答案 0 :(得分:0)

你的课应该是这样的:

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; }
}

需要将字节数组转换为代码中的某个图像:

using (MemoryStream ms = new MemoryStream(imgBytes)) {
  this.User_Image = Image.FromStream(ms);
}

答案 1 :(得分:-3)

public void BindRepeater (DataSet dsObj)
{
   pictureBox1.DataBindings.Clear();
   pictureBox1.DataBindings.Add("ImageLocation", dt, "Photo");
   dataRepeater1.DataSource = dsObj;

 }