RadDataEntry need some qualified help.

2 posts, 0 answers
  1. Jesse
    Jesse avatar
    3 posts
    Member since:
    Jul 2014

    Posted 22 Aug 2014 Link to this post

    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.
  2. Dess
    Admin
    Dess avatar
    1609 posts

    Posted 22 Aug 2014 Link to this post

    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.
     
  3. UI for WinForms is Visual Studio 2017 Ready
Back to Top