This is a migrated thread and some comments may be shown as answers.

RadDataEntry need some qualified help.

1 Answer 89 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
Jesse
Top achievements
Rank 1
Jesse asked on 22 Aug 2014, 09:39 AM
Greetings, i've a RadDataEntry, everything works well now...but it seems there's a problem. I've an image in byte[], and i need to display it properly, as image. And after all it still MUST be correctly binded to the base entity, where this field is byte[] and not an image, in case if i'll change image to another one.

1 Answer, 1 is accepted

Sort by
0
Dess | Tech Support Engineer, Principal
Telerik team
answered on 22 Aug 2014, 01:34 PM
Hello Jesse,

Thank you for writing.

By default RadDataEntry generates several different editors according to the data type of the property that it should edit. The default editors are listed in our Change auto generated editor help article. Here is a sample code snippet, demonstrating how to display image in the RadDataEntry:
private void Form1_Load(object sender, EventArgs e)
{
    this.categoriesTableAdapter.Fill(this.nwindDataSet.Categories);
 
    this.radDataEntry1.BindingCreating += radDataEntry1_BindingCreating;
    this.radDataEntry1.BindingCreated += radDataEntry1_BindingCreated;
    this.radDataEntry1.EditorInitializing += radDataEntry1_EditorInitializing;
    this.radDataEntry1.ItemInitializing += radDataEntry1_ItemInitializing;
     
    this.radBindingNavigator1.BindingSource = this.categoriesBindingSource;
    this.radDataEntry1.DataSource = this.radBindingNavigator1.BindingSource;
}
 
private void radDataEntry1_ItemInitializing(object sender, ItemInitializingEventArgs e)
{
    if (e.Panel.Controls[1].Text == "Picture")
    {
        e.Panel.Location = new Point(5, 90);
        e.Panel.Size = new Size(200, 50);
    }
}
 
private void radDataEntry1_BindingCreating(object sender, BindingCreatingEventArgs e)
{
    if (e.DataMember == "Picture")
    {
        e.PropertyName = "Image";
    }
}
 
private void radDataEntry1_BindingCreated(object sender, BindingCreatedEventArgs e)
{
    if (e.DataMember == "Picture")
    {
        e.Binding.Format += Binding_Format;
    }
}
 
private void Binding_Format(object sender, ConvertEventArgs e)
{
    byte[] byteArrayIn = e.Value as byte[];
    e.Value = ImageHelper.GetImageFromBytes(byteArrayIn);
}
 
private void radDataEntry1_EditorInitializing(object sender, EditorInitializingEventArgs e)
{
    if (e.Property.Name == "Picture")
    {
        PictureBox pictureBox = new PictureBox();
        pictureBox.SizeMode = PictureBoxSizeMode.StretchImage;
        e.Editor = pictureBox;
    }
}

In the above mentioned help article you can pay attention to the Binding.Format and the Binding.Parse events in order to set up correct binding.

I hope this information helps. Should you have further questions, I would be glad to help.

Regards,
Desislava
Telerik
 
Check out Telerik Analytics, the service which allows developers to discover app usage patterns, analyze user data, log exceptions, solve problems and profile application performance at run time. Watch the videos and start improving your app based on facts, not hunches.
 
Tags
General Discussions
Asked by
Jesse
Top achievements
Rank 1
Answers by
Dess | Tech Support Engineer, Principal
Telerik team
Share this question
or