A.Goutam
A.Goutam

Reputation: 3494

Item cannot be added to a read-only or fixed-size list

I am using bindingsource . The problem is that when i do AddNew() in binding source then it give me the exception Item cannot be added to a read-only or fixed-size list. This form is Dialog. For your review i am adding the code

Main Form Code

private void bindingNavigatorAddNewItem_Click_1(object sender, EventArgs e)
{
    try
    {
        this.Validate();
        _earning = (Earning)this.earningBindingSource.Current;
        string EmpNo = Convert.ToString(_earning.Empno == null || _earning.Empno == string.Empty ? "0" : _earning.Empno);
        Incomes.frmIncomeAddList _earnEmployee = new Incomes.frmIncomeAddList();
        _earnEmployee.ShowDialog();
    }
    catch (Exception ex)
    {
    }
}

This is the Dialog Form Code

public frmIncomeAddList( )
{
    InitializeComponent();  

    FillCurrency();

    FillDropdown();
    FillEarnCode();
    FillEarnCodeDESC();

    this.earningBindingSource.AddNew();

    this.earningBindingNavigatorSaveItem.Enabled = true;

    FillDropdown(); 
}

on Dialog Form this.earningBindingSource.AddNew(); i am getting exception Item cannot be added to a read-only or fixed-size list.

Can you please help me. Thank's in advance

Upvotes: 0

Views: 2549

Answers (3)

Ahmed Suror
Ahmed Suror

Reputation: 500

Make sure that YourBindingSource.AllowNew = true;

Or from properties window of the BindingSource:

enter image description here

It worked for me..

Upvotes: 1

when parent table has no record, and add new row in child table then show this error.

Item cannot be added to a read-only or fixed-size list

Upvotes: 1

Hargoth
Hargoth

Reputation: 11

Try this approach:

List<Earning> earnings = ((IEnumerable<Earning>)earningBindingSource.DataSource).ToList();
earnings.Add(new Earning());
earningBindingSource.DataSource = earnings.AsEnumerable();

Upvotes: 1

Related Questions