Auto Populated Data

2 posts, 0 answers
  1. Mark
    Mark avatar
    12 posts
    Member since:
    Oct 2012

    Posted 12 Jun 2015 Link to this post

    I have a dataentry that I want to set values for certain textboxes when a user adds a new item/entry. I can access the controls but nothing shows up in the text box at runtime.

    1.private void rs40AddNewItem_Click(object sender, EventArgs e)
    2.        {
    3.            Mix _mix = new Mix();
    4.            (radDataEntry1.PanelContainer.Controls["radPanel4"].Controls[0] as RadTextBox).Text = "TEST";
    5.        }

    I am not sure if this is the right approach.

  2. Dess
    Dess avatar
    1561 posts

    Posted 16 Jun 2015 Link to this post

    Hello Mark,

    Thank you for writing.

    Here is a sample code snippet demonstrating how the RadDataEntry and RadBindingNavigator are set up on my end. The "Add" button is enabled when a parameter-less constructor for the custom class is available. In order to initialize the generated editors with default values, you can initialize the respective properties in the constructor.
    public Form1()
        BindingList<Item> items = new BindingList<Item>();
        for (int i = 0; i < 3; i++)
            items.Add(new Item(i,"Item" + i));
        BindingSource bs = new BindingSource();
        bs.DataSource = items;
        this.radDataEntry1.DataSource = bs;
        this.radBindingNavigator1.BindingSource = bs;
    public class Item
        public int Id { get; set; }
        public string Name { get; set; }
        public Item()
            this.Id = -1;
            this.Name = "Enter some name";
        public Item(int id, string name)
            this.Id = id;
            this.Name = name;

    Alternatively, when you add a new item, the BindingSource.Current property is changed and the item will be displayed. Here is the appropriate place to modify the editors' values:
    bs.CurrentChanged += bs_CurrentChanged;
    bs.AddingNew += bs_AddingNew;

    bool isItemAdded = false;
    private void bs_AddingNew(object sender, AddingNewEventArgs e)
        isItemAdded = true;
    private void bs_CurrentChanged(object sender, EventArgs e)
        if (isItemAdded)
            isItemAdded = false;
            (this.radDataEntry1.PanelContainer.Controls[0].Controls[0] as RadTextBox).Text = "10"
            (this.radDataEntry1.PanelContainer.Controls[1].Controls[0] as RadTextBox).Text = "TEST";

    I hope this information helps. Should you have further questions, I would be glad to help.
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
  3. DevCraft R3 2016 release webinar banner
Back to Top