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

Auto Populated Data

1 Answer 92 Views
DataEntry
This is a migrated thread and some comments may be shown as answers.
Mark
Top achievements
Rank 1
Mark asked on 12 Jun 2015, 07:51 PM

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.

1 Answer, 1 is accepted

Sort by
0
Dess | Tech Support Engineer, Principal
Telerik team
answered on 16 Jun 2015, 07:24 AM
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()
{
    InitializeComponent();
    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.
 
Regards,
Dess
Telerik
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
Tags
DataEntry
Asked by
Mark
Top achievements
Rank 1
Answers by
Dess | Tech Support Engineer, Principal
Telerik team
Share this question
or